Stijndcl
05/03/2024, 4:01 PM{
"type": "user",
"some_other_field": "some_other_value",
...
}
where in the case of a User
, the content of some_other_field
indicates a different subclass to be used to deserialize it. This has an example in the docs: https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/json.md#content-based-polymorphic-deserialization
but this doesn't play nicely if it's nested in something else. Stripped-down/simplified version of what I have now:
@Serializable
sealed class Base
@Serializable(with = ContentBasedUserDeserializer::class)
@SerialName("user")
sealed class User : Base()
@Serializable
data class FirstUserType : User()
I found an issue on GitHub about nested polymorphism, but it says it would be covered in 1.x and hasn't been updated in 4 years.
If what I'm doing right now is not supported, is there a workaround to deserialize the data I have now?Stijndcl
05/05/2024, 11:50 AMJsonContentPolymorphicSerializer
s.