Joshua Hansen
02/19/2025, 10:59 PMname
and a `value`:
sealed interface MyInterface<T : Any> {
val name: String
var value: T
}
There's a bunch of subclasses which implement this interface with different types:
class MyClass1(override var value: Boolean) : MyInterface<Boolean> {
override val name: String = "Foo"
}
class MyClass2(override var value: String) : MyInterface<String> {
override val name: String = "Bar"
}
I want to write a custom generic serializer which serializes these classes to/from a string of this format:
"$name=${/* String Serialized form of value */}"
I have a list of these in a parent class, like this:
class Parent {
val myList: List<MyInterface<*>> = listOf()
}
Is it possible to serialize/deserialize Parent
and ensure each member of the list is deserialized into the appropriate class instance? I'm not using JSON format. (I'm using KAML for YAML serialization)