I need help with this error `Sealed class cannot b...
# serialization
I need help with this error
Sealed class cannot be serialized as base class because it has property name that conflicts with JSON class discriminator 'type'. You can either change class discriminator in JsonConfiguration, rename property with @SerialName annotation or fall back to array polymorphism
Please note that changing the class discriminator causing the API to reject the payload.
Copy code
sealed class Message { abstract type: String }

sealed class MessageHeader { abstract type: String }

data class VideoHeader( override val type: String, val video: Media ): MessageHeader

data class TextMessage( override val type: String, text: String, header: MessageHeader ): Message
I'm not sure I understand what you want to do – you can't currently use a property as a discriminator (https://github.com/Kotlin/kotlinx.serialization/issues/1664). If you just want to have a
field in the JSON, you can remove the property and set the values for the classes via the
annotation. If you want both, you'll have to go custom.
Hi @hho I've created a sealed class named "`Message`" to handle serialization and deserialization of various message types required by the application. Within the "`Message`" object, there's a sealed class called "`Header`" which manages different message headers like image, video, document, and text. However, the deserialization process encounters an issue because both the parent and child classes share the same property name. If i'm not mistake the default JSON class discriminator is '`type`' and when I remove header everything works.