My application is supposed to receive a JSON message through an HTTP request and I'm using a custom deserializer to map the LocalDateTime properties of some of my classes. But, when I receive the information through JsonParser the month is offset by -1.
E.g. The message that is sent is: "2020-10-12T10:20:00.000Z" and the message that is inside the JsonParser is: "2020-09-12T10:20:00.000Z".
I'm using Jackson 2.9.6 and SpringBoot 2.1.3. Any ideas what could be the cause of this?
@Override
public LocalDate deserialize(final JsonParser p, final DeserializationContext ctxt)
throws IOException {
final String date = p.readValueAs(String.class);
if (date == null) {
return null;
}
try {
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
ZonedDateTime dateToParse = ZonedDateTime.parse(date, DateTimeFormatter.ISO_DATE_TIME);
return dateToParse.toLocalDate();
} catch (final DateTimeParseException ex) {
LOGGER.error(ex.getMessage());
return null;
}
}
My issue is at "final String date = p.readValueAs(String.class)". p contains the value that is received and its Month is offset by -1.