Upgrading Spring Boot from 2.4.1 to 2.6.1, getting `java.time.Instant` not supported by default error

Viewed 1809

When I upgrade the Spring Boot App from 2.4.1 to 2.6.1. I got the below error.

com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Java 8 date/time type java.time.Instant not supported by default: add Module "com.fasterxml.jackson.datatype:jackson-datatype-jsr310" to enable handling (through reference chain: org.springframework.boot.actuate.trace.http.HttpTrace["timestamp"])

1 Answers

With an upgrade from Spring Boot 2.4 to 2.6, you also upgrade Jackson from 2.11 to 2.13. And Jackson 2.12 contains the following change: https://github.com/FasterXML/jackson-databind/issues/2683

This produces the error message that you are seeing as the JSR 310 module is now compulsary if the corresponding date times are used.

You should only be affected by this, when you configure your own ObjectMapper such that the auto-configured one backs off. At the point where you configure that ObjectMapper, you need to explicitly add the JSR 310 module. That can be done with code like this:

objectMapper.registerModule(new JavaTimeModule());

There is also is a somewhat lengthy but insightful discussion on github about this: https://github.com/spring-projects/spring-boot/issues/26859

Related