Remo
07/23/2022, 1:32 PMsealed interface Convertible {
fun convertUserInput(value : String): String
}
@Serializable
@SerialName("CustomConvertible")
class CustomConvertible(): Convertible {
override fun convertUserInput(value : String): String {
return ""
}
}
@Serializable
class DTOAttribute(val convertibles : List<Convertible> = emptyList())
Later on, I’d like to encode the DTOAttribute
with val string = Json.encodeToString(dtoAttr)
Calling this, gives me the following exception:
kotlinx.serialization.SerializationException: Class 'CustomConvertible' is not registered for polymorphic serialization in the scope of 'Convertible'.
Mark the base class as 'sealed' or register the serializer explicitly.
What am I doing wrong?ephemient
07/23/2022, 4:27 PMsealed class
or upgrade to Kotlin 1.6.20 https://github.com/Kotlin/kotlinx.serialization/issues/1576ephemient
07/23/2022, 4:31 PM@Serializable
Remo
07/23/2022, 7:17 PM