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?
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.