Open Robsmon opened 6 months ago
Quick note: I think (but cannot canonically claim as the official answer) that the default TimeZone
is only meant to be used in absence of explicit one; at least with default settings.
However. Since you mention WRITE_DATES_WITH_CONTEXT_TIME_ZONE
, enabling that... oh.
It does look like it should be enabled since 2.13.
(as the background this default timezone was most useful for java.util.Date
, instances of which do not have timezone specified and must use something if serialized as String value).
So maybe this is indeed working incorrectly. But aside from fixing this (and testing properly), there is then the question of backwards-compatibility -- I think this might be acceptable for a minor version (even if others might argue otherwise). But would need to be considered carefully.
As stated in the Jackson ObjectMapper the default should be UTC for writing Json:
https://github.com/FasterXML/jackson-databind/blob/b8910125bba81862ea278821ccfd198b1f69fd5d/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java#L2529-L2537
https://github.com/FasterXML/jackson-databind/blob/b8910125bba81862ea278821ccfd198b1f69fd5d/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java#L408-L422
With the java 8 time module when the timezone is set to null no time zone information is used on serialisation as the provider.getConfig().hasExplicitTimeZone() does result in false if the default of null is set. So ZonedDateTime is not written with utc as default.
https://github.com/FasterXML/jackson-modules-java8/blob/38f979fbe16a03344f08d6ca899204b7c3bc1afb/datetime/src/main/java/com/fasterxml/jackson/datatype/jsr310/ser/InstantSerializerBase.java#L147-L163
Is this expected behavior to not overwrite the TimeZone defined in the ZonedDateTime? Than this should be properly Documented.
Minimal example: