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.

Parse Kotlin metadata manually to honor nullability and avoid kotlin-metadata-jvm dep

See original GitHub issue

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 request(@Body 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.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:61
  • Comments:29 (8 by maintainers)

github_iconTop GitHub Comments

118reactions
claucookiecommented, Jul 26, 2019

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 Response<Unit> in the retrofit method declaration.

I use Retrofit 2.6.0.

60reactions
JakeWhartoncommented, Apr 12, 2019

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 notifications@github.com 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 request(@Body 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 https://github.com/square/retrofit/issues/3075, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEEEb6RFk0-5aDUMDF6fMlN9U2r9w7Hks5vf9MHgaJpZM4crGCw .

Read more comments on GitHub >

github_iconTop Results From Across the Web

Null safety | Kotlin
Null safety. Nullable types and non-null types. Kotlin's type system is aimed at eliminating the danger of null references, also known as ...
Read more >
Retrofit:responseBodyがnullのsuspend関数を定義する
Parse Kotlin metadata manually to honor nullability and avoid kotlin-metadata-jvm dep · Issue #3075 · square/retrofit.
Read more >
Using GSON with Kotlin's Non-Null Types | by Clay Gillman
With more and more people using Kotlin, it was inevitable that programmers would use it alongside the most popular Java JSON library, ...
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