No content to map due to end-of-input jackson parser
import com.fasterxml.jackson.core.JsonParser.Feature;
import com.fasterxml.jackson.databind.ObjectMapper;
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(res, StatusResponses.class);//replaced result.getResponseAsString() with res
} catch (Exception e) {
e.printStackTrace();
}
Don't know how it worked and why it worked? :( but it worked
java.io.EOFException: No content to map to Object due to end of input while retrieving data
To return an empty map you have to use the below:
mapper.readValue("{}", Map.class);
Because an empty string ""
doesn't mean empty JSON. An empty JSON is indicated by {}
. On Similar lines an empty array in JSON is indicated by []
Spring Rest Docs error - "No content to map due to end-of-input"
Your tests using MockMvc
are not setting an Accept
header in the POST
request. That means that, by default, Spring Data REST does not include a body in its 201 Created response. You either need to configure Spring Data REST to always return a body for create requests or you need to change your tests to send an Accept
header.
REST POST controller saying: Could not read JSON: No content to map due to end-of-input
I replaced the .param() methods in favor of the .content() one:
post("/admin/crud").headers(httpHeaders)
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON)
.content("{ \"firstname\" : \"" + admin0.getFirstname() + "\", \"lastname\" : \"" + admin0.getLastname() + "\", \"email\" : \"" + admin0.getEmail() + "\", \"login\" : \"" + admin0.getLogin() + "\", \"password\" : \"" + admin0.getPassword() + "\", \"passwordSalt\" : \"" + admin0.getPasswordSalt() + "\" }")
).andDo(print())
.andExpect(status().isCreated())
.andExpect(jsonPath("$.firstname").value(admin0.getFirstname()))
.andExpect(jsonPath("$.lastname").value(admin0.getLastname()))
.andExpect(jsonPath("$.email").value(admin0.getEmail()))
.andExpect(jsonPath("$.login").value(admin0.getLogin()))
.andExpect(jsonPath("$.password").value(admin0.getPassword()))
.andExpect(jsonPath("$.passwordSalt").value(admin0.getPasswordSalt()))
.andReturn();
And it now works as expected.
Related Topics
How to Send List of Long to Rest Controller Spring Boot
Java 8 Streams - How to Merge Elements from the List With the Same Fields to One Element and Sum Up
Showing Morning, Afternoon, Evening, Night Message Based on Time in Java
Replace Whitespace in Json Keys
Createprocess Error=2, the System Cannot Find the File Specified
Reverse a String Without Affecting Special Characters
Could Not Read Json: Can Not Deserialize Instance of Hello.Country[] Out of Start_Object Token
Retrieving Data from Biometric Fingerprint Attendance Device
Flush/Clear System.In (Stdin) Before Reading
Gradle: How to Exclude a Particular Package from a Jar
How to Get Numbers from Given Gcd and Lcm
How to Store User Input into an Existing Array
In Java: How to Zip File from Byte[] Array
Eclipse: the Resource Is Not on the Build Path of a Java Project
Forwarding the Request from One Jsp to Another Jsp With All Request Parameters
Regular Expression to Remove Everything But Characters and Numbers