Jackson loses time offset from dates when deserializing to JodaTime Jackson loses time offset from dates when deserializing to JodaTime json json

Jackson loses time offset from dates when deserializing to JodaTime


Jackson must be told to not adjust the time-zone to that of the local context by:

mapper.disable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE);

See this issue on GitHub


Yes, this is by design. JodaTime DateTimeSerializer use standard toString() method. According to JodaTime official guide toString() returns - the standard ISO8601 string for the DateTime. Also, standard DateTimeDeserializer always creates UTC datetimes.

To store TimeZone you need to store it separately with same json and use .withZone() method after deserialization or just create serializer and deserializer.

UPDATE

Version 2.2.3 have a bit extended behaviour - DateTimeDeserializer creates DateTime with timeZone taken from DeserializationContext. it may be changed with ObjectMapper.setTimeZone(). Default is TimeZone.getTimeZone("GMT")


From the Javadoc for AbstractInstant#equals() which is a superclass of DateTime:

Compares this object with the specified object for equality based on the millisecond instant, chronology and time zone. (my emphasis)

Two objects which represent the same instant in time, but are in different time zones (based on time zone id), will be considered to be different. Only two objects with the same DateTimeZone, Chronology and instant are equal.

The two dates you show designate the same instant, but since they have different timezones JodaTime says they're not "equal". I don't see anything wrong with how Jackson is handling them.