No content to map due to end-of-input
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.
public class Order {
public long id;
public String status;
}
Order order = mapper.readValue(json, Order.class);Line 6 changes.
public class Order {
public long id;
public String status;
}
Order order = json.isBlank() ? null : mapper.readValue(json, Order.class);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.
- 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
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.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.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
readValueon 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.