I have a need to de-serialize time of format 2016-11-28T10:34:25.097Z using Jackson into ZonedDateTime of Java8.
I believe I correctly configured O
I needed to serialize/deserialize a date in ISO8601 Zulu format 2016-11-28T10:34:25.097Z like you
I chose to change the date formatter in ObjectMapper using ISO8601DateFormat
like this
@Bean
ObjectMapper getObjectMapper() {
ObjectMapper objectMapper = new ObjectMapper();
// some other config...
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
objectMapper.setDateFormat(new ISO8601DateFormat());
return objectMapper;
}
In my optinion the following JsonFormat for ISO 8601
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX")
is much better, since this format is more intuitive to read and allows timezones like ACST with UTC offset of +09:30 too.
The problem is probably with 'Z' in the pattern. It does not allow literal 'Z' in the date time value. Try 'X' instead.
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSX")