No content to map due to end-of-input

ErrorJava

com.fasterxml.jackson.databind.exc.MismatchedInputException: No content to map due to end-of-input

What it means

Jackson was given an empty string, so there was nothing to read. Check for an empty body before you call readValue, then find out why it was empty.

Last verified on Jackson 2.21 and 3.1; Spring 6.2 and 7.0.

The body was empty, so there is no JSON to check.

Usually
The body is emptyAn empty response or requestThe body was already read
Fix
Check the body before you read it, as in the fixed code: json.isBlank() ? null : mapper.readValue(json, Order.class).

The fix

Check the body before you read it, as in the fixed code: json.isBlank() ? null : mapper.readValue(json, Order.class). Then find out why it was empty. That is usually the real bug.

Broken.javaThrows
public class Order {
  public long id;
  public String status;
}

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

Line 6 changes.

Fixed.javaWorks
public class Order {
  public long id;
  public String status;
}

Order order = json.isBlank() ? null : mapper.readValue(json, Order.class);
Reads without an error.

How the message appears

Jackson 2, then Jackson 3, then Spring (the same on 6.2 and 7.0). Jackson 2 gives a line but no column, and Jackson 3 gives an unknown byte offset.

Console
  • com.fasterxml.jackson.databind.exc.MismatchedInputException: No content to map due to end-of-input
  • at [Source: REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); line: 1]
  • tools.jackson.databind.exc.MismatchedInputException: No content to map due to end-of-input
  • at [Source: REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); byte offset: #UNKNOWN]
  • org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: No content to map due to end-of-input

What causes it

  1. The body is empty

    The example is an empty string. There is nothing to read, so Jackson 2 and 3 both say No content to map due to end-of-input.

  2. An empty response or request

    Whatever made the body empty, this is the message. Look for a response with no body, or a call that failed before it returned anything. Spring's Jackson converter prints it as JSON parse error: No content to map due to end-of-input. Whether an empty request ever gets as far as the converter depends on what runs before it in your app, which was not tested here. Other Spring messages are on the Spring page.

  3. The body was already read

    A stream can only be read once. If something read the body before Jackson, Jackson gets nothing. Look for a logging filter or a second readValue on the same stream.

Worth knowing

Watch outReturning null for an empty body only moves the problem. The code after the call now has to handle null.

NoteJavaScript fails on an empty string too, with Unexpected end of JSON input.

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.