https://kotlinlang.org logo
h

hagabaka

02/28/2018, 3:09 PM
what I've done is have a
Data
class with nullable fields, and a
Base
class with a custom serializer which calls
input.readValue() as Data
in
load
and checks the null fields and constructs the right subtype
s

sandwwraith

02/28/2018, 5:15 PM
basically,
input.readValue()
is not sufficient for deserializing, logic there is much more complicated – you should call
readBegin()
, then read primitives field-by-field and so on. You can take a look on standard collection serializers (https://github.com/Kotlin/kotlinx.serialization/blob/master/runtime/common/src/main/kotlin/kotlinx/serialization/internal/CollectionSerializers.kt#L58 and https://github.com/Kotlin/kotlinx.serialization/blob/master/runtime/jvm/src/main/kotlin/kotlinx/serialization/PolymorphicSerializer.kt#L37) to get an idea what happens there
h

hagabaka

02/28/2018, 5:20 PM
oh, it seems like changing it to
input.read(Data::class.serializer())
worked, but I'm still testing it