Java 8 date/time type java.time.LocalDateTime not supported by default
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 (or disable `MapperFeature.REQUIRE_HANDLERS_FOR_JAVA8_TIMES`)
What it means
A plain Jackson 2 ObjectMapper does not know the java.time types, so it fails on a LocalDateTime. Register JavaTimeModule on the mapper and the same JSON reads.
Last verified on Jackson 2.21 and 3.1; Spring 6.2 and 7.0.
This JSON is valid. The problem is on the Java side, so a JSON validator would say it is fine.
- Usually
- A plain new ObjectMapper on Jackson 2Writing fails tooIt works in Spring but fails in your testJackson 3 does not have this problem
- Fix
- On Jackson 2, add the
jackson-datatype-jsr310dependency and register the module once on the mapper:mapper.registerModule(new JavaTimeModule());.
The fix
On Jackson 2, add the jackson-datatype-jsr310 dependency and register the module once on the mapper: mapper.registerModule(new JavaTimeModule());. On Jackson 3 you need nothing.
{
"id": 7,
"createdAt": "2026-10-14T09:30:00"
}public class Order {
public long id;
public LocalDateTime createdAt;
}
Order order = mapper.readValue(json, Order.class);Line 6 changes.
public class Order {
public long id;
public LocalDateTime createdAt;
}
mapper.registerModule(new JavaTimeModule());
Order order = mapper.readValue(json, Order.class);How the message appears
Only a plain Jackson 2 ObjectMapper throws this, so there is no Jackson 3 or Spring line. First the error when reading, with where it stopped. Then the same error when writing, which has no position because nothing is being read.
- 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 (or disable `MapperFeature.REQUIRE_HANDLERS_FOR_JAVA8_TIMES`)
- at [Source: REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); line: 3, column: 16] (through reference chain: com.example.Order["createdAt"])
- 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 (or disable `MapperFeature.REQUIRE_HANDLERS_FOR_JAVA8_TIMES`) (through reference chain: com.example.Order["createdAt"])
What causes it
A plain new ObjectMapper on Jackson 2
new ObjectMapper()on Jackson 2 has no handler forLocalDateTime. The message names the module to add,jackson-datatype-jsr310. The JSON is fine.Writing fails too
It is not only reading. Writing an
Orderwith aLocalDateTimethrough the same mapper throws the same message. That one has noat [Source: ...]part, only the field:com.example.Order["createdAt"].It works in Spring but fails in your test
With
jackson-datatype-jsr310on the classpath, Spring's converter read this JSON with no error. A mapper you create yourself withnew ObjectMapper()does not. So a unit test or a helper class can fail while the app works. See the Spring page.Jackson 3 does not have this problem
Jackson 3 reads
LocalDateTimewith no module and no setup, and so does Spring 7. If you see this error, it comes from Jackson 2.
Worth knowing
Watch outThe message also mentions MapperFeature.REQUIRE_HANDLERS_FOR_JAVA8_TIMES. Turning that off was not tested here. Adding the module is the fix the message gives first.