If I have: ```@Serializable(with = FooSerializer::...
# serialization
l
If I have:
Copy code
@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?
s
If you try to (de)serialize them when they are of type
Foo
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.
Copy code
@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? 👀
l
That's what should happen afaik, yeah
s
l
Ic, so yeah, it works like I expected. Will have to write some more of these, ig.