Laxystem
04/08/2024, 3:31 PM@Serializable(with = FooSerializer::class)
public sealed interface Foo
Then will all subclasses of Foo
be serialized with FooSerializer
, or do I need to create a serializer for them too?Stylianos Gakis
04/08/2024, 3:42 PMFoo
then this will be used.
If you have a subclass, and then you try to (de)serialize something and you give the function that other class instead, it will not automatically find the FooSerializer
to use.
That is my understanding of this feature at least.
@Serializable(with = FooSerializer::class)
public sealed interface Foo
@Serializable
class A : Foo
@Serializable
Class B : Foo
val fooInstance: Foo = A()
val aInstance: A = A()
Json.decodeFromString(fooInstance)
Json.decodeFromString(aInstance)
The first decodeFromString
should use that serializer
The second one should not.
Maybe try to write something like this locally and run it, and put a log inside the FooSerializer to see if that is in fact the case? 👀Laxystem
04/08/2024, 3:43 PMStylianos Gakis
04/08/2024, 3:44 PMLaxystem
04/08/2024, 3:46 PM