@sandwwraith not sure if I’m running into a compiler bug or its desired behavior but I have a somewhat complex heirarchy I’m trying to serialize with an interface at its apex. Let me see if I can do this justice but my
graph looks like:
interface Field<Value> {...}
interface InputField<InputT> : Field<InputT> {...}
interface SelectorField<ValueT> : Field<ValueT> {...}
abstract class NumberField : InputField<Number> {...}
abstract class BooleanField : SelectorField<Boolean> {...}
@Serializable
data class NumberFieldImpl(...): NumberField()
@Serializable
data class BooleanFieldImpl(...): BooleanField()
Also I have a custom _map_:
// Need to add serializable on base class else compiler complains
@Serializable
abstract class MapBackedContainer<K, V>(val storage: MutableMap<K, V>) : MutableMap<K, V> by storage
@Serializable // Currently fails compile, message below
class FieldContainer : MapBackedContainer<String, Field<*>>
@Serializable // This one has no errors, ActionImpl is non generic and annotated with @Serializable
class ActionContainer : MapBackedContainer<String, ActionImpl>
FieldContainer
currently fails compile with the message
“Serializer for element of type Any? has not been found. To use context serializer as fallback, explicitly annotate element with @Contextual”.
I tried adding
@Serializable
on the intermediate abstract classes of
Field<*>
but the issue is the same. Same with adding
@Contextual
on the Field<*> generic parameter of FieldContainer.