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

Default DateTime parser format is stricter than previous versions, causing incompatibility #70

Closed
jamesmcmillan opened this issue Jul 27, 2015 · 1 comment
Milestone

Comments

@jamesmcmillan
Copy link

In this commit, for DateTimeSerializer:
cf2f4c2#diff-86756f80e06fe3b0a847c963534b14baR55

DateTime.parse() is replaced by using the JacksonJodaDateFormat, which defaults to FormatConfig.DEFAULT_DATETIME_FORMAT, which is defined as new JacksonJodaDateFormat(ISODateTimeFormat.dateTime().withZoneUTC()).

DateTime.parse() uses ISODateTimeFormat.dateTimeParser().withOffsetParsed():
http://www.joda.org/joda-time/apidocs/org/joda/time/DateTime.html#parse-java.lang.String-

So ultimately, the default date time parser format has changed from ISODateTimeFormat.dateTimeParser() to ISODateTimeFormat.dateTime(). Although similar, ISODateTimeFormat.dateTimeParser() is much less restrictive:
http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime--
http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTimeParser--

As an example, the datetime "2015-07-27T08:11:07-07:00" is missing the .SSS milliseconds value, so it fails in 2.6.0 but works in 2.5.4:

Caused by: java.lang.IllegalArgumentException: Invalid format: "2015-07-27T08:11:07-07:00" is malformed at "-07:00"
    at org.joda.time.format.DateTimeFormatter.parseDateTime(DateTimeFormatter.java:899) ~[joda-time-2.8.1.jar:2.8.1]
    at com.fasterxml.jackson.datatype.joda.deser.DateTimeDeserializer.deserialize(DateTimeDeserializer.java:90) ~[jackson-datatype-joda-2.6.0.jar:2.6.0]
    at com.fasterxml.jackson.datatype.joda.deser.DateTimeDeserializer.deserialize(DateTimeDeserializer.java:22) ~[jackson-datatype-joda-2.6.0.jar:2.6.0]
    at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:520) ~[jackson-databind-2.6.0.jar:2.6.0]
    at com.fasterxml.jackson.databind.deser.impl.FieldProperty.deserializeAndSet(FieldProperty.java:101) ~[jackson-databind-2.6.0.jar:2.6.0]
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:256) ~[jackson-databind-2.6.0.jar:2.6.0]

A workaround in this situation is to add a @JsonFormat annotation to the property specifying the specific format, e.g: @JsonFormat(pattern="yyyy-MM-dd'T'HH:mm:ssZZ")

@cowtowncoder
Copy link
Member

Ugh. I am surprised to find that said underlying change actually changes behavior, so change was definitely not intentional. I thought I had looked briefly at patterns to make sure they fit with expected ones, but I think I was assuming that if names (of constants) matched, underlying patterns would too.

Should be fixed for 2.6.1.

@cowtowncoder cowtowncoder added this to the 2.6.1 milestone Jul 28, 2015
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