Need some help here to serialize a property in a c...
# serialization
p
Need some help here to serialize a property in a class that is a list of an interface. Specifically at line 47 I need to add something like
@Serializable(with = ????) val list: List<Stuff>
. But what ???? is is eluding me.
d
p
You mean for the hundredth time?
p
Not that I can see. I've read this page many times. What would be more helpful, and something I could not find is an example of encoding a property that is an array of an interface. The PolymorphicSerializer doc page only shows how to deal with a list of class, not a list of an interface. List of class is working for me, not list of interface, at least not yet.
d
An interface itself cannot be serialized, you need to specify list of possible subclasses as seen in the docs for PolymorphicSerializer
1
p
Hmmm. You might be right. I'll mull that one for a bit ... is this a limitation for collections? I can certainly serialize interfaces that are not collections as long as the implementations are registered using a polymorphic serializer like JsonContentPolymorphicSerializer. Use that all the time. This is my first attempt with a collection of an interface.
It turns out you can serialize a list of interfaces, as I was trying to do. The solution comes from @Sergey Shanshin on Github and is hugely appreciated!