-
Notifications
You must be signed in to change notification settings - Fork 7.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot cast response body to Custom class with Void as response type #1963
Comments
Using |
But when I was declaring User as Response Type, I was getting onResponse() callback when api returns user but when api returns null I am getting onFailure() callback (where I could not find the reason of failure which might be deserialising issue). |
In that case the failure exception indicates the problem that needs corrected. Please include its entire stacktrace. |
Here is the stack trace:
|
Looks like your server returns a 0-byte body in that case. You can use a custom converter that returns |
In my case responseBody.contentLength() is giving me -1 though responseBody.string() is correct (as sent from api). On adding this converter my service ends with onFailure() callback. |
I am using retrofit2, my use case calls an api which can either return with a response class (say User) or with null. So I am using
Void
response type. My onReponse() is shown below:But I am getting IllegalStateException. Is it something wrong with the code.
The text was updated successfully, but these errors were encountered: