Paulius Ruminas
06/18/2019, 2:12 PMsealed class A {
@Serializable
data class B(val type: String) : A()
}
@Test
fun main() {
val json = Json(
configuration = JsonConfiguration.Common,
context = SerializersModule {
polymorphic<A> {
addSubclass<A.B>()
}
}
)
val s = PolymorphicSerializer(A::class)
val j = json.stringify(s, A.B(type = "Test"))
json.parse(s, j)
}
The code will produce error: Test is not registered for polymorphic serialization in the scope of class A
The error occurs because there are two type
fields. If it is possible it would be nice that this name clash issue would be reported at compile time or if it is not possible I think there should be a better error message that states that one has two type
fields and it is impossible to resolve the polymorphic type. What do you think?sandwwraith
06/18/2019, 4:35 PM