Skip to content
Advertisement

Springboot 2.5.6 gives java.time.temporal.UnsupportedTemporalTypeException: Unsupported field: OffsetSeconds issues

Since migration to springboot 2.5.6 I have to register our ObjectMapper with JavaTimeModule. However, I am getting the below error for the format "yyyy-MM-dd'T'HH:mm:ss.SSSZ". How can I fix it?

The input time that we get is something like 2020-07-01T10:00:00.000+0000

mapper = new ObjectMapper()
            .registerModule(new JavaTimeModule())
            .registerModule(new Jdk8Module());

Error

 java.time.temporal.UnsupportedTemporalTypeException: Unsupported field: OffsetSeconds 

Our Serialization

@JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZ", shape = JsonFormat.Shape.STRING

Advertisement

Answer

LocalDateTime does not support timezones by definition. Therefore it doesn’t support OffsetSeconds.

You should leave off the +0000 in the input and the Z in the format. Alternatively, use ZonedDateTime instead.

I don’t know which version of Spring Boot you were using before, but maybe it was using an older version of Jackson which used JSR10Module.

From the JavaTimeModule docs: https://fasterxml.github.io/jackson-modules-java8/javadoc/datetime/2.9/com/fasterxml/jackson/datatype/jsr310/JavaTimeModule.html

Note that as of 2.6, this module does NOT support auto-registration, because of existence of legacy version, JSR310Module. Legacy version has the same functionality, but slightly different default configuration: see JSR310Module for details.

From the JSR310Module docs: https://fasterxml.github.io/jackson-modules-java8/javadoc/datetime/2.9/com/fasterxml/jackson/datatype/jsr310/JavaTimeModule.html

Old JSR310Module defaults to serialization WITH Timezone Ids (to support round-trippability of values when using JSR-310 types and Jackson)

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement