I have the following class strucutre: ``` @Seriali...
# serialization
k
I have the following class strucutre:
Copy code
@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?
d
Where have you registered it?
k
What do you mean?
d
How do you serialize?
Json.stringify
?
k
No a custom encoder / decoder build on
ElementValueEncoder
and
ElementValueDecoder
To simplify it reads a string and splits it on the spaces
d
Ah I see.
k
The problem is that to deserialise
foo foobar
it would need to read 2 strings. But I can't do that without coding it into the reader.
d
Polymorphism is not sup..... exactly!
That's how it's done in the Json one.
k
?