Hi, I am still struggling with tree-like serialize...
# serialization
a
Hi, I am still struggling with tree-like serializers. I have following serializeable node:
Copy code
data class NodeItem<M : Meta>(val node: M) : MetaItem<M>() {
        override fun toString(): String = node.toString()

        @Serializer(NodeItem::class)
        companion object : KSerializer<NodeItem<out Meta>> {
            ...
        }
    }
M
is the recursive generics type. It is actually ignored in the serializer since we always use top type. When I use it, I get
class hep.dataforge.meta.MetaBuilder is not registered for polymorphic serialization in the scope of class hep.dataforge.meta.Meta
. Is it possible to somehow bypass polymorphic serializers and actually use interface type for serialization?
I solved the problem with writing
Copy code
@Serializable(MetaSerializer::class) val node: M
. I guess it could cause classcast errors, but will hold for now.