You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Ideally I would write sealed class Value, but is there a way to let kotlinx.serialization pick up the correct serializer for value based on the property control. Moreover the control property is not an object type discriminator, but different prefixes maps to different values. In Jackson once can use TypeIdResolver for this.
I tried to write some custom serializer - while serialization is just fine, the deserialization is problematic - since there is no guarantee the control property comes sooner than value so the code below doesn't work:
loop@ while (true) {
when (val i = compositeDecoder.decodeElementIndex(descriptor)) {
CompositeDecoder.READ_DONE->break@loop
0-> control = compositeDecoder.decodeStringElement(descriptor, i)
1-> value = compositeDecoder.decodeSerializableElement(descriptor, i, chooseSerializer(control))
else->throwSerializationException("Unknown index $i")
}
}
Additionaly I didn't find a way how to "remember raw value" for later decoding based on control
Thanks for help
The text was updated successfully, but these errors were encountered:
Some API returns json like this:
Ideally I would write
sealed class Value
, but is there a way to let kotlinx.serialization pick up the correct serializer for value based on the propertycontrol
. Moreover the control property is not an object type discriminator, but different prefixes maps to different values. In Jackson once can useTypeIdResolver
for this.I tried to write some custom serializer - while serialization is just fine, the deserialization is problematic - since there is no guarantee the
control
property comes sooner thanvalue
so the code below doesn't work:Additionaly I didn't find a way how to "remember raw value" for later decoding based on
control
Thanks for help
The text was updated successfully, but these errors were encountered: