Skip to content

@JsonFormat.pattern on dates is now ignored if shape is not explicitely provided #1154

@yrodiere

Description

@yrodiere

Since #1111 was merged, JsonFormat.pattern is now only taken into account if the shape is set to STRING. When leaving the default shape (ANY), the pattern is ignored.

Thus this works:

public class Person
{
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-mm-dd")
    public Date dateOfBirth;
}

But this doesn't (anymore):

public class Person
{
    @JsonFormat(pattern = "yyyy-mm-dd") // Uses default shape, which is ANY
    public Date dateOfBirth;
}

From what I understand of DataTimeSerializerBase's code, it seems that the default "shape" for a date-time is a String (see how _asTimestamp returns false by default). So it seems that providing a pattern should work with the shape ANY, which means "the default shape", which is STRING.

The issue stems from this line . It should be something like this instead:

if (format.getShape() == JsonFormat.Shape.STRING || format.getShape() == JsonFormat.Shape.ANY) {

PR coming as soon as I have the issue ID.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions