]> juplo.de Git - website/blob
c82278fe82e42e546bca0aa8e4ccc3d1f696f453
[website] /
1 ---
2 _edit_last: "3"
3 author: kai
4 categories:
5   - jackson
6   - java
7   - leitmarkt-wettbewerb-createmedia.nrw
8 date: "2015-11-12T15:12:05+00:00"
9 guid: http://juplo.de/?p=554
10 parent_post_id: null
11 post_id: "554"
12 title: How To Keep The Time-Zone When Deserializing A ZonedDateTime With Jackson
13 url: /how-to-keep-the-time-zone-when-deserializing-a-zoneddatetime-with-jackson/
14
15 ---
16 ## The Problem: Jackson Loses The Time-Zone During Dezerialization Of A ZonedDateTime
17
18 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.
19 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.
20
21 This behavior is very unintuitive and not well documented.
22 [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.
23
24 ## The Solution: Tell Jackson, Not To Adjust the Time-Zone
25
26 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.
27 Tis can be done with this line of code:
28
29 ```java
30 mapper.disable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE);
31 ```
32
33 ## Funded by the Europian Union
34
35 This article was published in the course of a
36 [resarch-project](http://yourshouter.com/projekte/crowdgest%C3%BCtzte-veranstaltungs-suchmaschine.html "Show details about the funded resarch-project"),
37 that is funded by the European Union and the federal state Northrhine-Wetphalia.
38
39 [![Europäische Union: Investitionen in unsere Zukunft - Europäischer Fonds für regionale Entwicklung](/img/EFRE_Foerderhinweis_deutsch_farbig.svg)![EFRE.NRW 2014-2020: Invesitionen in Wachstum und Beschäftigung](/img/Ziel2NRW_4c_1809_eps.svg)](http://yourshouter.com/projekte/crowdgest%C3%BCtzte-veranstaltungs-suchmaschine.html "Show details about the funded resarch-project")