question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

200 Empty body fails (retrofit:2.0.0)

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

7reactions
azlanjamalcommented, Jun 3, 2016

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.

1reaction
gurappacommented, Sep 29, 2015

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Empty body in retrofit 2 - android - Stack Overflow
i have a scenario that when you do a PUT on a end point and get an OK http code 200, ...
Read more >
onFailure gets called even after 200 status code #1446 - GitHub
The response body is empty but you are asking Gson to deserialize it as some type. This is the disagreement between the response...
Read more >
Retrofit2 doesn't handle empty content responses - Ken Yee
The workaround is to add a null delegating converter in front of the JSON converter for Retrofit2. class NullOnEmptyConverterFactory implements Converter.
Read more >
Oauth/request_token returning 200 but with empty body
I am getting a response back for the first step (oauth/request_token) which has a 200 code, but the response body is completely empty....
Read more >
How to handle RESTful web Services using Retrofit, OkHttp ...
Quick setup for Retrofit 2 just to try it first · First, give INTERNET permission for the app · Then you should add...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found