Changelog of version 2.5.0 is misleading regarding Unit support
See original GitHub issueQuoting the changelog:
New: Built-in support for Kotlin’s Unit type. This behaves the same as Java’s Void where the body content is ignored and immediately discarded.
If you try to use a suspending function returning no meaningly value (i.e. Unit), with a backend sending a 204 No-Content response for example, you end up with a runtime failure: the infamous KotlinNullPointerException.
To me, this is quite contradictory with changelog of version 2.5.0, and it’s unclear how Unit is supported.
Also, the test for Kotlin’s Unit is not actually written in Kotlin.
The suspending functions support test is in Kotlin, but it doesn’t test no return value (Unit) in the service proxied by Retrofit. If it is not supported, it’d good to have it written clearly somewhere (along with new doc for Kotlin usage?), and a test that is asserting it fails with KNPE would be good. I lost hours of my time trying to understand why it doesn’t pick the built-in Unit converter, and still don’t have an answer, hours I’d have preferred to spend on something more useful. I prefer to not imagine how beginners would face this.
If support is not there yet, I can submit a doc update PR.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:8 (3 by maintainers)

Top Related StackOverflow Question
Well for my application every single
PUThas no body so a function like this:Is the perfect representation of that call. I assume this is quite a common case.
Now I’m understanding my past experiences, where I had a custom
awaitSuccess()extension function before built-in non 204/205Unitsupport was integrated. When I updated, I tried and it didn’t work, so I did a quick revert and forgot about it.There may be less folks in my situation that I initially thought then.