I'm trying to deserialize an ISO8601 formatted date into Java8 java.time.Instant
using Jackson. I registered JavaTimeModule with the ObjectMapper, and turned off the WRITE_DATES_AS_TIMESTAMPS
setting.
However, if one tries to deserialize 2016-03-28T19:00:00.000+01:00
it will not work, because it seems that JavaTimeModule will only deserialize date-times formatted with UTC timezone offset (e.g. 2016-03-28T18:00:00.000Z
). I then tried using @JsonFormat
annotation like this:
@JsonFormat(shape=JsonFormat.Shape.STRING, pattern="yyyy-MM-dd'T'HH:mm:ss.SSSZ", timezone = "UTC")
And like this:
@JsonFormat(shape=JsonFormat.Shape.STRING, pattern="yyyy-MM-dd'T'HH:mm:ss.SSSZ", timezone = JsonFormat.DEFAULT_TIMEZONE)
However, neither of these work and I get an exception:
com.fasterxml.jackson.databind.JsonMappingException: Unsupported field: YearOfEra (through reference chain: org.example.Article["date"])
Which implies that timezone parameter is ignored and date time formatter doesn't know how to format an Instant without a timezone.
Is there a way to deserialize a ISO8601 string that's not in UTC time zone offset to Java 8 java.time.Instant
using Jackson and JavaTimeModule without writing a custom deserializer?
Failed to parse Date value '2016-03-28T19:00:00.000+01:00' (format: "yyyy-MM-dd'T'HH:mm:ss.SSSZ"): Unparseable date: "2016-03-28T19:00:00.000+01:00"
and after trying your code, I got this kind of error in both cases. The format is not matching... did you tried it without any annotations? – Anthologize