]> juplo.de Git - website/blob
540c8a00fcea0b6927cc8baf0636123c3f95846b
[website] /
1 ---
2 _edit_last: "3"
3 categories:
4   - tips
5 tags:
6   - jackson
7   - java
8   - createmedia.nrw
9 date: "2015-11-12T15:12:05+00:00"
10 guid: http://juplo.de/?p=554
11 parent_post_id: null
12 post_id: "554"
13 title: How To Keep The Time-Zone When Deserializing A ZonedDateTime With Jackson
14 url: /how-to-keep-the-time-zone-when-deserializing-a-zoneddatetime-with-jackson/
15
16 ---
17 ## The Problem: Jackson Loses The Time-Zone During Dezerialization Of A ZonedDateTime
18
19 In its default configuration [Jackson](http://wiki.fasterxml.com/JacksonHome "Visit the homepage of the Jackson-project") adjusts the time-zone of a `ZonedDateTime` to the time-zone of the local context.
20 As, by default, the time-zone of the local context is not set and has to be configured manually, Jackson adjusts the time-zone to GMT.
21
22 This behavior is very unintuitive and not well documented.
23 [It looks like Jackson just loses the time-zone during deserialization](http://stackoverflow.com/questions/19460004/jackson-loses-time-offset-from-dates-when-deserializing-to-jodatime/33674296 "Read this question on Stackoverflow for example") and, [if you serialize and deserialize a `ZonedDateTime`, the result will not equal the original instance](https://github.com/FasterXML/jackson-datatype-jsr310/issues/22 "See this issue on the jackson-datatype-jsr310 on GitHub"), because it has a different time-zone.
24
25 ## The Solution: Tell Jackson, Not To Adjust the Time-Zone
26
27 Fortunately, there is a quick and simple fix for this odd default-behavior: you just have to tell Jackson, not to adjust the time-zone.
28 Tis can be done with this line of code:
29
30 ```java
31 mapper.disable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE);
32 ```