1.0.1 but I think this bug also exists in 1.1.2
Only tested with GSON, may be Jackson is also affected.
Already noticed in #157. The nullable Kotlin type is not taken into account by the GSON deserialization.
Kotlin Data class:
data class Something(val value: String)
Data in HTTP:
{}
Result:
Something(value=null)
We have to add the nullable property on all data class fields.
If any non-nullable field is not fulfilled, the deserialization should return null (or throw if <T> receiveOrNull() is not used).
Hi @scorsi, thanks for the report.
It's obviously a bug and we'll fix it in the next release.
It looks like we need this done to perform the null check: https://github.com/google/gson/issues/445
You also could add zero argument constructor as a workaround.
Just fyi, also affects Jackson :)
Current workaround:
suspend inline fun <reified T : Any> ApplicationCall.safeReceiveOrNull(): T? = try {
receiveOrNull()
} catch (e: Exception) {
null
}
Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.
Most helpful comment
Hi @scorsi, thanks for the report.
It's obviously a bug and we'll fix it in the next release.