Skip to content

StdDateFormat fails to parse 'zulu' date when TimeZone other than UTC #1651

@brenuart

Description

@brenuart

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions