retrofit: 200 Empty body fails (retrofit:2.0.0)

Hi,

Noticed an issue when receiving a 200 response with an empty body.

Using the jackson-converter.

com.fasterxml.jackson.databind.JsonMappingException: No content to map due to end-of-input
 at [Source: java.io.InputStreamReader@2fc6f97f; line: 1, column: 1]
    at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:148)
    at com.fasterxml.jackson.databind.ObjectReader._initForReading(ObjectReader.java:381)
    at com.fasterxml.jackson.databind.ObjectReader._bindAndClose(ObjectReader.java:1494)
    at com.fasterxml.jackson.databind.ObjectReader.readValue(ObjectReader.java:1119)
    at retrofit.JacksonResponseBodyConverter.convert(JacksonResponseBodyConverter.java:33)
    at retrofit.JacksonResponseBodyConverter.convert(JacksonResponseBodyConverter.java:23)
    at retrofit.OkHttpCall.parseResponse(OkHttpCall.java:144)
    at retrofit.OkHttpCall.execute(OkHttpCall.java:112)
    at retrofit.ExecutorCallAdapterFactory$ExecutorCallbackCall.execute(ExecutorCallAdapterFactory.java:60)

However this call works correctly if the response has status code 204 or 205.

Is there any way around this?

Cheers

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 15 (6 by maintainers)

Most upvoted comments

Hi, how to handle an API that return empty response if response is success and return a response “Error”:“SessionKeyExpired” when response is failed. Both are successful API call scenario. I try to use Void but that would cause no way to handle the “Error”. Thank you.

Sorry for bring up last year’s thread.

Hi @JakeWharton,

Void did not work for me either. But ResponseBody worked.

One more issue is that when my request returns 404 NOT FOUND, retrofit called onSuccess() of callback. It’s the same result when I used Void, ResponseBody and JSONObject in Callback.

Could you please elaborate on how it works so that we will have a single code for all cases empty/success, empty/failure, body/success and body/failure ? Or any link to doc ?

Thanks, Guru