This question is about deserialization to Joda-Time DateTime using jackson-datatype-joda module for Jackson. Is there a default timezone that date strings will be deserialized into? If so, what is it? Is it UTC?
I need to ask this because the Jackson documentation is not specific for Joda-Time DateTime. I found in this article (http://wiki.fasterxml.com/JacksonFAQDateHandling) that Jackson will assume GMT as the default time zone for deserializing into java.util.Date
or java.util.Calendar
. However, there is no mention of Joda-Time data types in this document. In addition, I specifically need strings to deserialize into DateTime
objects using the UTC timezone, not GMT: although these two zones are very similar, there are some small differences and therefore GMT will not be feasible for me.
Thank you.
Best Answer
The source code for
DateTimeDeserializer
shows it uses the timezone fromDeserializationContext
which is provided byObjectMapper
during deserialization. If you look atObjectMapper
API, you will see there is method for setting the timezone:Thus you can use this method to configure your
ObjectMapper
and set the timezone to the correct one.For what concerns the default value, it seems the Javadoc says one thing, but the code shows another.
Javadoc for
ObjectMapper.setTimeZone(TimeZone tz)
:However, the code sets the timezone explicitly on:
So, apparently, it actually uses GMT, and not the default JVM default.
I would say that probably the best choice would be not relying on this and set it by yourself on
ObjectMapper.setTimeZone(TimeZone tz)
.