I’m seeing a weird behavior with v0.12.0 (and 0.11...
# serialization
l
I’m seeing a weird behavior with v0.12.0 (and 0.11.1) where I’m trying to deserialize a data class, using
Json.nonstrict
with Retrofit 2.6.1. The field is a String, and with it on my class I receive the message:
Copy code
Field 'full_name' is required, but it was missing
but if I remove it then I get:
Copy code
Encountered an unknown key full_name
The field exists in the generated class under
build/classes/kotlin/main/
and it gets removed when I comment the field out. How can I see what’s happening when deserializing it?
s
Do you have such filed in class definition?
l
yes, this is how the class is defined:
Copy code
@Serializable
data class AuthResponse(
  @SerialName("full_name") val full_name: String,
  @SerialName("token") val token: String
)
s
Well, indeed this is required filed, and if it is not present in your JSON, it is an error.
If such key is present and JSON, but strictness validation fails, it's a bug; I'll check if this behaviour is present
l
i agree, but the field is present. Passing
prettyPrint = true
to my json configuration shows it
Using
Json.plain
I also get the same error. On this case I added a new field to the deserialized model due to its strictness but that’s not need on the client app.
Also happens on the newly released
0.13.0
s
This code works fine for me:
Copy code
val input = """{"full_name":"A","token":"B"}"""
        println(Json.nonstrict.parse(AuthResponse.serializer(), input))
println(Json.parse(AuthResponse.serializer(), input))
l
Is there something that i can try in order to find where the problem might be? peeking into the generated code, or maybe some flag to get debug logs?
s
Unfortunately, there's no available way to debug generated code. You can see it (via action 'show kotlin bytecode' -> then decompile to Java), but afair breakpoints there won't work
👍 1