Kroppeb
09/27/2019, 12:33 PM@Serializable
@Polymorphic
sealed class Command {
companion object { val context = SerializersModule {
polymorphic(CommandTest::class) {
addSubclass(Function.serializer())
addSubclass(Foo.serializer())
}
include(Foo.context)
}}
@Serializable
@SerialName("function")
class Function(val name:String): Command()
@Serializable
@SerialName("foo")
@Polymorphic
sealed class Foo : Command(){
companion object { val context = SerializersModule {
polymorphic(Foo::class) {
addSubclass(FooBar.serializer())
}
}}
@Serializable
@SerialName("foobar")
class FooBar(val x:Int, val y: Int, val z: Int): Foo()
}
}
And I have a reader that reads each time to the next space.
I want FooBar
to be serialised and deserialised by foo foobar
but if i try deserialised it says foo
isn't registered and I get a NPE when serialising.
Is there a way to do this?Dominaezzz
09/27/2019, 12:58 PMKroppeb
09/27/2019, 12:59 PMDominaezzz
09/27/2019, 1:00 PMJson.stringify
?Kroppeb
09/27/2019, 1:01 PMElementValueEncoder
and ElementValueDecoder
Kroppeb
09/27/2019, 1:02 PMDominaezzz
09/27/2019, 1:03 PMKroppeb
09/27/2019, 1:03 PMfoo foobar
it would need to read 2 strings. But I can't do that without coding it into the reader.Dominaezzz
09/27/2019, 1:03 PMDominaezzz
09/27/2019, 1:04 PMKroppeb
09/27/2019, 1:04 PM