Am I correct in my understanding that I can't... ...
# serialization
d
Am I correct in my understanding that I can't... Have a subclass with a property named
irrelevantName
with
@SerialName("type")
of a sealed class annotated with
@JsonClassDiscriminator("something_else")
with my Json built as
Json { classDiscriminator = "type" /* default */ }
due to the
"type"
in the
@SerialName
conflicting with the
classDiscriminator
that ISN'T the class discriminator used on the parent sealed class?
I'm assuming this because I see the exception:
Copy code
07-31 10:33:53.212 E/AndroidRuntime( 4685): Caused by: java.lang.IllegalArgumentException: Polymorphic serializer for class com.seatgeek.android.dayofevent.mytickets.api.model.MyTicketsBuzzfeedContentList has property 'type' that conflicts with JSON class discriminator. You can either change class discriminator in JsonConfiguration, rename property with @SerialName annotation or fall back to array polymorphism
07-31 10:33:53.212 E/AndroidRuntime( 4685): 	at kotlinx.serialization.json.internal.PolymorphismValidator.checkDiscriminatorCollisions(PolymorphismValidator.kt:67)
07-31 10:33:53.212 E/AndroidRuntime( 4685): 	at kotlinx.serialization.json.internal.PolymorphismValidator.polymorphic(PolymorphismValidator.kt:34)
07-31 10:33:53.212 E/AndroidRuntime( 4685): 	at kotlinx.serialization.modules.SerialModuleImpl.dumpTo(SerializersModule.kt:189)
07-31 10:33:53.212 E/AndroidRuntime( 4685): 	at kotlinx.serialization.json.JsonImpl.validateConfiguration(Json.kt:375)
07-31 10:33:53.212 E/AndroidRuntime( 4685): 	at kotlinx.serialization.json.JsonImpl.<init>(Json.kt:369)
07-31 10:33:53.212 E/AndroidRuntime( 4685): 	at kotlinx.serialization.json.JsonKt.Json(Json.kt:191)
07-31 10:33:53.212 E/AndroidRuntime( 4685): 	at kotlinx.serialization.json.JsonKt.Json$default(Json.kt:187)
07-31 10:33:53.212 E/AndroidRuntime( 4685): 	at com.seatgeek.android.gson.SeatGeekJson$serializer$2.invoke(SeatGeekJson.kt:72)
07-31 10:33:53.212 E/AndroidRuntime( 4685): 	at com.seatgeek.android.gson.SeatGeekJson$serializer$2.invoke(SeatGeekJson.kt:71)
07-31 10:33:53.212 E/AndroidRuntime( 4685): 	at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
07-31 10:33:53.212 E/AndroidRuntime( 4685): 	at com.seatgeek.android.gson.SeatGeekJson.getSerializer(SeatGeekJson.kt:71)
If I set the
JsonBuilder.classDiscriminator
to some arbitrary value, this works. But it seems the fact that purely the default discriminator matches on this polymorphic hierarchy causes it to fail validation at runtime