-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed
Milestone
Description
The StdDateFormat
fails to properly parse 'zulu' dates when the ObjectMapper has its timezone set to other than UTC. It appears the parser removes the trailing Z
when found and construct a new java.util.Date
instance using the timezone of the mapper instead of forcing it to UTC.
The example below illustrates the problem. It parses the representation of EPOCH in zulu format once with the mapper in its default configuration and a second time with its timezone set to GMT+1.
Because the trailing Z
should be considered as a UTC timezone indicator, both cases should lead to the same date which is not the case.
String json = "\"1970-01-01T00:00:00.000Z\"";
// Standard mapper with timezone UTC
ObjectMapper mapper = new ObjectMapper();
Date dateUTC = mapper.readValue(json, Date.class); // 1970-01-01T00:00:00.000+00:00
// Mapper with timezone GMT+1
mapper.setTimeZone(TimeZone.getTimeZone("GMT+1"));
Date dateGMT1 = mapper.readValue(json, Date.class); // 1969-12-31T23:00:00.000+00:00
// Both dates should be the same
Assert.assertEquals(dateUTC.getTime(), dateGMT1.getTime()); // FAIL
Metadata
Metadata
Assignees
Labels
No labels