Paulius Ruminas

    Paulius Ruminas

    3 years ago
    Hi, I have encountered an error because of discriminator field name clash:
    sealed class A {
        data class B(val type: String) : A()
    fun main() {
        val json = Json(
            configuration = JsonConfiguration.Common,
            context = SerializersModule {
                polymorphic<A> {
        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
    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
    fields and it is impossible to resolve the polymorphic type. What do you think?


    3 years ago