I have a json that holds a list of polymorphic objects,
{
"someList": [
{ "type": "A", "value": {"aProp": false } },
{ "type": "B", "value": {"bProp": "1" } },
]
}
which represents a type hierarchy like this one:
sealed class Base
class A(val aProp: Boolean): Base()
class B(val aProp: String): Base()
class BaseList(val someList: List<Base>)
I would like to deserialize the JSON into such types,
but the default seales/polymorphic kotlinx serializer reads & writes the discriminator in the object itself, like this:
{
"someList": [
{ "type": "A", "aProp": false },
{ "type": "B", "bProp": "1" }
]
}
while I got the discriminator outside of the object itself.
How can I deserialize such a JSON into this Kotlin type hierarchy?