No content to map due to end-of-input jackson parser

前端 未结 11 1873
盖世英雄少女心
盖世英雄少女心 2020-12-23 19:00

I am getting this response from the server {\"status\":\"true\",\"msg\":\"success\"}

I am trying to parse this json string using Jackson parser library

相关标签:
11条回答
  • 2020-12-23 19:20

    This error is sometimes (often?) hiding the real problem: a failure condition could be causing the content to be incorrect, which then fails to deserialize.

    In my case, today, I was making HTTP calls and (foolishly) omitted to check the HTTP status code before trying to unmarshal the body of the response => my real problem was actualy that I had some authentication error, which caused a 401 Unauthorized to be sent back to me, with an empty body. Since I was unmarshalling that empty body directly without checking anything, I was getting this No content to map due to end-of-input, without getting any clue about the authentication issue.

    0 讨论(0)
  • 2020-12-23 19:24

    I got this error when sending a GET request with postman. The request required no parameters. My mistake was I had a blank line in the request body.

    0 讨论(0)
  • 2020-12-23 19:25

    I had a similar error today and the issue was the content-type header of the post request. Make sure the content type is what you expect. In my case a multipart/form-data content-type header was being sent to the API instead of application/json.

    0 讨论(0)
  • 2020-12-23 19:29

    The problem for me was that I read the response twice as follows:

    System.out.println(response.body().string());
    getSucherResponse = objectMapper.readValue(response.body().string(), GetSucherResponse.class);
    

    However, the response can only be read once as it is a stream.

    0 讨论(0)
  • 2020-12-23 19:32

    I know this is weird but when I changed GetMapping to PostMapping for both client and server side the error disappeared.

    Both client and server are Spring boot projects.

    0 讨论(0)
提交回复
热议问题