FasterXML / jackson-modules-java8

Set of support modules for Java 8 datatypes (Optionals, date/time) and features (parameter names)
Apache License 2.0
401 stars 117 forks source link

Deserialization of `ZonedDateTime` may lose zone information #118

Closed hohwille closed 5 years ago

hohwille commented 5 years ago

On Deserialization of ZonedDateTime the ZoneId is added as offset and lost resulting in "1999-12-31T23:59:59+02:00" being deserialized as "1999-12-31T21:59:59Z[UTC]". I traced it down to the root which is here: https://github.com/FasterXML/jackson-modules-java8/blob/master/datetime/src/main/java/com/fasterxml/jackson/datatype/jsr310/deser/InstantDeserializer.java#L209

IMHO one would need to use ZonedDateTime.parse(CharSequence) to properly deserialize ZonedDateTime.

See also https://github.com/devonfw/devon4j/issues/116

cowtowncoder commented 5 years ago

Did you try disabling DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE? That was added to allow control over whether TimeZone is to be unified or not.

cowtowncoder commented 5 years ago

I think that this might be good issue for new contributors to investigate.

kupci commented 5 years ago

@hohwille Did disabling the DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE solve the issue for you? That looks like it should work, though I notice there isn't any documentation on this setting, or at least I couldn't find it, so I added a 'Documentation Needed' label to this item.

kupci commented 5 years ago

Found the documentation: https://github.com/FasterXML/jackson-databind/wiki/Deserialization-Features

kupci commented 5 years ago

With the update to the README, I think this can be closed. There are also a bunch of tests that exercise the functionality (@see TestZonedDateTimeSerialization) though if additional tests are helpful, please re-open and they can be added.

hohwille commented 4 years ago

Sorry for the late response but I can confirm that your suggestion fixed the issue. Thanks for the hint and great that you also updated to docs 👍