Issue
I'm getting java.io.UncheckedIOException: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Java 8 date/time type
java.time.LocalDateTime not supported by default: add Module "com.fasterxml.jackson.datatype:jackson-datatype-jsr310" to enable handling
when I upgraded to sprngboot 2.5.6. I tried several solutions from online but doesn't see to work for me. Added the below dependencies
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.11.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jdk8</artifactId>
</dependency>
Have the below custom object mapper but disabling it doesn't work either
@Bean
@Primary
public ObjectMapper objectMapper() {
return new ObjectMapper()
.setSerializationInclusion(JsonInclude.Include.NON_NULL)
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.registerModule(new JavaTimeModule())
.registerModule(new Jdk8Module())
.registerModule(new DefaultScalaModule())
.enable(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE)
.findAndRegisterModules();
Solution
I was able to fix this using ZonedDateTime
instead of LocalDateTime
.
Answered By - user3310115
Answer Checked By - David Marino (JavaFixing Volunteer)