No Content to Map Due to End-Of-Input Jackson Parser

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



Leave a reply



Submit