Were there major changes to deserializing dynamic ...
# serialization
r
Were there major changes to deserializing dynamic objects from JS in Serialization 1.0.0-RC? I know the API has changed to merge the
DynamicObjectParser
into
Json
, but when trying to use
.decodeFromDynamic()
I'm getting
Copy code
IllegalStateException: This serializer can be used only with Json format.Expected Decoder to be JsonDecoder, got class DynamicInput
The serializer in this case is a small data class annotated with
@Serializable
, and I've also tried using
JsonObject.serializer()
with the same results. How can I handle serializing a dynamic from a JS library into a Kotlin object in this case?
v
It seems to be a bug, especially if it worked before. Could you please provide a reproducer?
JsonObject.serializer()
 with the same results.
Are we talking about JsonObject serialization to dynamic here?
r
Opposite direction, trying to get a dynamic output from a JS library into a JsonObject.
v
Was it working before 1.0.0-RC?
r
This is new code that I didn't have prior to updating, but I'd used the DynamicObjectParser in the past in 0.20.0 in a similar way and it worked fine. I was trying to determine if there were any changes to how dynamic object decoding worked beyond the syntax changes that were auto-suggested. I can't find any documentation on decodeFromDynamic() to validate that I haven't missed something. I have:
Copy code
@Serializable
data class DecodedJwt(val header: JsonObject, val payload: JsonObject, val signature: String)

val payload = jsonwebtoken_decode(token, jsObject {complete = true; json = true} as DecodeOptions)
            val parsedPayload = Json{}.decodeFromDynamic<DecodedJwt>(payload)
where
jsonwebtoken_decode
is an external declaration that returns dynamic
The final line where .decodeFromDynamic<>() is called is where the error is being thrown from
I can step through in the IntelliJ Debugger and see that the dynamic object is coming back as expected
v
Thanks, filed https://github.com/Kotlin/kotlinx.serialization/issues/1080 It doesn’t seem to be working prior to 1.0.0-RC either, but it’s still a bug that should be fixed. We only have syntactic,
decodeFromDynamic
actually invokes
DynamicPbjectParser.parse
under the hood
r
Thanks for your help and filing that! Good to know I wasn't just doing something wrong all along 🙂