Another question: how can I create a deserializer ...
# serialization
l
Another question: how can I create a deserializer that supports two forms?
m
If you only need to support JSON, you could create a
JsonContentPolymorphicSerializer
that picks between the two options. Or just a serializer that deserializes to JsonElement or what every is the most common base and then manually parse from there.
a
If you have a custom KSerializer you can check the type of the encoder/decoder and behave differently. There's an example in the docs that checks if the encoder is a JsonEncoder https://github.com/Kotlin/kotlinx.serialization/blob/v1.6.3/docs/json.md#under-the-hood-experimental
l
@Michael Krussel thanks, that's what I needed! I think I'll just use sealed interfaces for this one though.