Bao Le Duc
02/16/2023, 9:18 AMJsonClassDiscriminator
is not found?
Background: I have a data class
@Serializable
@JsonClassDiscriminator("type")
sealed interface Messaging {
@Serializable
@SerialName("inc_messaging_usermsg")
data class UserMsg(
val content: String
) : Messaging
@Serializable
@SerialName("inc_messaging_youfollow")
data class YouFollow(
val name: String
) : Messaging
@Serializable
@SerialName("inc_messaging_usermsgwdata")
data class UsermsgWithData(
val attachment: MessagingAttachment
) : Messaging
/**
* object Default : Messaging
*/
}
As we may add new type of messages in the future, I would add object Default : Messaging
as a fallback option if new type is introducedDominaezzz
02/16/2023, 10:13 AMBao Le Duc
02/16/2023, 10:14 AMkotlinx.serialization.json.internal.JsonDecodingException: Polymorphic serializer was not found for class discriminator 'some unknown type'
Dominaezzz
02/16/2023, 10:16 AMBao Le Duc
02/16/2023, 10:21 AMpolymorphicDefaultDeserializer(MessagingPayload::class) {
UnkownMessagingPayload.serializer()
}
Thanks for the tips @DominaezzzJorge Rodríguez
02/16/2023, 7:37 PMtype
discriminator.