. Advertisement .
..3..
. Advertisement .
..4..
Using the Jackson parser package, I am attempting to parse this JSON string, however I am getting mapping-exceptions that state: no content to map due to end-of-input.
com.fasterxml.jackson.databind.JsonMappingException: No content to map due to end-of-input
at [Source: java.io.StringReader@421ea4c0; line: 1, column: 1]
Why do we encounter such exceptions?
How can I determine the reason for this exception? Help me fix it, please. Thanks a lot.
I’m attempting to parse using the method below:
StatusResponses loginValidator = null;
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(Feature.AUTO_CLOSE_SOURCE, true);
try {
String res = result.getResponseAsString();//{"status":"true","msg":"success"}
loginValidator = objectMapper.readValue(result.getResponseAsString(), StatusResponses.class);
} catch (Exception e) {
e.printStackTrace();
}
StatusResponse class
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({ "status","msg" })
public class StatusResponses {
@JsonProperty("status")
public String getStatus() {
return status;
}
@JsonProperty("status")
public void setStatus(String status) {
this.status = status;
}
@JsonProperty("msg")
public String getMessage() {
return message;
}
@JsonProperty("msg")
public void setMessage(String message) {
this.message = message;
}
@JsonProperty("status")
private String status;
@JsonProperty("msg")
private String message;
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
@JsonGetter
public Map<String, Object> getAdditionalProperties() {
return additionalProperties;
}
@JsonSetter
public void setAdditionalProperties(Map<String, Object> additionalProperties) {
this.additionalProperties = additionalProperties;
}
}
The cause: In most cases, the issue was brought on by my sending the ObjectMapper.readValue call a null InputStream. In another scenario, the client side was the issue. I didn’t shut the server stream I was writing to by accident.
Solution: