0

I have a call to send data to the server. If everything is ok, the server returns a void response. But when there is an error I get data back.

To manage the case when there is an error I have a CustomResponse object. The issue is that when the request is successful Retrofit throws an Exception with the message: java.io.EOFException: End of input at line 1 column 1 path $

Here is the call:

@POST("/updateObject")
Observable<CustomResponse> updateObject(@Body CustomObject requestData);

I did a bit of researches and I read that I could use Observable<Response<Void>> ... but in that case how I'm supposed to manage when the response contains data?

Eselfar
  • 3,759
  • 3
  • 23
  • 43
  • what's the actual response when its successful though? is there really no body at all? – TooManyEduardos Jun 21 '17 at 16:29
  • The response is: `OkHttp: <-- END HTTP (0-byte body)` so there is really no body. – Eselfar Jun 21 '17 at 16:30
  • Possible duplicate of [How can I handle empty response body with Retrofit 2?](https://stackoverflow.com/questions/33228126/how-can-i-handle-empty-response-body-with-retrofit-2) – Sebastian Aug 15 '17 at 12:59
  • @NoActivity.java It partially solve the issue. I've personally solved it using [this answer](https://github.com/square/retrofit/issues/1554#issuecomment-178633697) – Eselfar Aug 15 '17 at 13:13

1 Answers1

0

I haven't tried this myself, but I would start with creating a wrapper class that has your CustomResponse as a nullable.

Something like this:

public class SomeWrapper {
    @Nullable CustomResponse customResponse;
}

Then in your Retrofit/Rx call, you can change it to this:

@POST("/updateObject")
Observable<SomeWrapper> updateObject(@Body CustomObject requestData);

give that a shot, and let me know if it works.

TooManyEduardos
  • 4,206
  • 7
  • 35
  • 66
  • Thx, but it doesn't work. Retrofit tries to parse the JSON but because there is no body it still fails. – Eselfar Jun 21 '17 at 16:45