-
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
Parse Kotlin metadata manually to honor nullability and avoid kotlin-metadata-jvm dep #3075
Comments
Not currently. I'm working on a parser for Kotlin metadata so we don't have
to depend on a gigantic jar to read one isNullable boolean.
…On Thu, Apr 11, 2019, 8:27 PM Aidan Laing ***@***.***> wrote:
Version: 2.6.0-SNAPSHOT
Exception: KotlinNullPointerException
Message: Response from {path to my suspend fun...} was null but response
body type was declared as non-null
The current structure of my suspend fun in my service interface:
@post("api/...")
suspend fun ***@***.*** body: Body): Response?
I'm using Gson for serialization.
Is there a way to declare the response body type as nullable that I'm
missing? I've tried adding null safety on my response object with ? and
@nullable with no success.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#3075>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAEEEb6RFk0-5aDUMDF6fMlN9U2r9w7Hks5vf9MHgaJpZM4crGCw>
.
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Hi there! Any chance to get update on this issue? :) Want to move to 2.6.0 and remove all other dependencies but can't cause of null response body not supported :( |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Just in case it helps. I was experiencing the exact same KotlinNPE issue over the last 2 days and after trying Converters and Adapters what really worked was to return I use Retrofit 2.6.0. |
Any progress? We've just changed some of our REST endpoints to 204. So I thought it would be enought to just remove response type (making it Using |
Because it doesn't provide the necessary info |
In this case retrofit does not throw any exception when got 4xx codes |
That is the expected behavior for that return type. |
Is it something that is open for a PR or do you want to implement it yourself in Retrofit or as an external project and use it here? I see that there is an old branch so I'd like to ask first before spending some time on it. |
Feel free to give it a shot
…On Tue, Feb 25, 2020, at 5:31 AM, Michał Sikora wrote:
Is it something that is open for a PR or do you want to implement it yourself in Retrofit or as an external project and use it here? I see that there is an old branch <https://github.com/square/retrofit/tree/jakew/nully/2019-02-15> so I'd like to ask first before spending some time on it.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#3075?email_source=notifications&email_token=AAAQIELMEQYZS3ED6MORGVDRETXOJA5CNFSM4HFMMCYKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEM3NYOQ#issuecomment-590797882>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAAQIENX2JYOB4K4V6XXXVDRETXOJANCNFSM4HFMMCYA>.
|
Found that empty response failed with the NPE mentioned. To cope with that problem, I wrapped all my backend json calls (on the backend side) inside an array. So if the result was empty, I returned an empty array at least. Just a tip to solve the problem if you have access and ability to change your backend data source. RG |
Retrofit doesn't support suspend function with nullable return Type square/retrofit#3075
Hi, to handle empty response only choice seems like Update: Using custom response converter suggested in #1554 works fine, (not converting empty body and returning null in such cases). But return type in API interface must be |
Are you sure? It looks to me like you can read "one |
Any new on this? How to handle 400 codes and empty body? Success called with the 400 error |
I have added wrong headers that caused me that HTTP 400 Bad request error. removing the following worked
|
@JakeWharton not any updates about this? Its been 2 years since issue has open :D |
right now I handled this by a simple try catch like this
|
Having an interceptor that rewrites the http 204 and 205 responses to 200 should work best. |
Hi, I hit this a few times recently, so I thought I'd give it a shot: #3544. Any feedback is welcome. |
If you get |
This saved me a lot of digging, was using a |
any suggestion for flow? |
Version: 2.6.0-SNAPSHOT
Exception: KotlinNullPointerException
Message: Response from {path to my suspend fun...} was null but response body type was declared as non-null
The current structure of my suspend fun in my service interface:
I'm using Gson for serialization.
Is there a way to declare the response body type as nullable that I'm missing? I've tried adding null safety on my response object with
?
and@Nullable
with no success.The text was updated successfully, but these errors were encountered: