Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
yrodiere opened this issue Mar 8, 2016 · 2 comments
Milestone

Comments

@yrodiere
Copy link
Contributor

yrodiere commented Mar 8, 2016

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.

@cowtowncoder
Copy link
Member

Thank you for reporting this. I think you are probably right with your assessment and this was just an oversight.

yrodiere added a commit to yrodiere/jackson-databind that referenced this issue Mar 8, 2016
Partially roll back to pre-FasterXML#1111 behavior.
We just make sure that the STRING shape is chosen when Shape.ANY (the default) is set on the annotation, but some other annotation attribute was also set (pattern, locale or timezone).
This way of fixing the issue has the added benefit of respecting the user config regarding the default serialization of strings when @jsonformat(shape = Shape.ANY) is set on a property.
@yrodiere yrodiere mentioned this issue Mar 8, 2016
yrodiere added a commit to yrodiere/jackson-databind that referenced this issue Mar 8, 2016
yrodiere added a commit to yrodiere/jackson-databind that referenced this issue Mar 9, 2016
yrodiere added a commit to yrodiere/jackson-databind that referenced this issue Mar 9, 2016
Partially roll back to pre-FasterXML#1111 behavior.
We just make sure that the STRING shape is chosen when Shape.ANY (the default) is set on the annotation, but some other annotation attribute was also set (pattern, locale or timezone).
This way of fixing the issue has the added benefit of respecting the user config regarding the default serialization of dates when @jsonformat(shape = Shape.ANY) is set on a property.
cowtowncoder added a commit that referenced this issue Mar 12, 2016
@cowtowncoder cowtowncoder added this to the 2.7.0 milestone Mar 15, 2016
@cowtowncoder
Copy link
Member

Fixed for 2.7.3.

@cowtowncoder cowtowncoder modified the milestones: 2.7.0, 2.7.3 Mar 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants