Java 8 date/time type java.time.LocalDateTime not supported by default

ErrorJava

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-jsr310 dependency 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.

The JSON that was sent: request.jsonValid JSON
{
  "id": 7,
  "createdAt": "2026-10-14T09:30:00"
}
A JSON validator says this is fine.
Broken.javaThrows
public class Order {
  public long id;
  public LocalDateTime createdAt;
}

Order order = mapper.readValue(json, Order.class);
Throws InvalidDefinitionException

Line 6 changes.

Fixed.javaWorks
public class Order {
  public long id;
  public LocalDateTime createdAt;
}

mapper.registerModule(new JavaTimeModule());
Order order = mapper.readValue(json, Order.class);
Reads without an error.

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.

Console
  • 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

  1. A plain new ObjectMapper on Jackson 2

    new ObjectMapper() on Jackson 2 has no handler for LocalDateTime. The message names the module to add, jackson-datatype-jsr310. The JSON is fine.

  2. Writing fails too

    It is not only reading. Writing an Order with a LocalDateTime through the same mapper throws the same message. That one has no at [Source: ...] part, only the field: com.example.Order["createdAt"].

  3. It works in Spring but fails in your test

    With jackson-datatype-jsr310 on the classpath, Spring's converter read this JSON with no error. A mapper you create yourself with new ObjectMapper() does not. So a unit test or a helper class can fail while the app works. See the Spring page.

  4. Jackson 3 does not have this problem

    Jackson 3 reads LocalDateTime with 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.

Your JSON and text are processed entirely in your browser and are never sent anywhere. To understand how the site is used we record each page view (the page, the referrer and an approximate location from your IP address) and keep it for 90 days. Nothing is stored on your device unless you choose it. Accept to also store a device identifier here and record your browser and device characteristics, which is what lets a return visit be told from a new one. Decline and nothing is sent at all. We respect Do Not Track. See our privacy policy.