functionaldude
03/31/2022, 3:18 PMJsonFeature
. I have the following class structure:
@Serializable
sealed class Base {
@Serializable
class Child: Base()
}
When I do a post request with Child()
as body, the class discriminator is missing (the body is just {}
). I figured out that `Child`’s serializer is used, if I use `Base`’s serializer then the class discriminator is there:
val payload = Base.Child()
val payloadString1 = kotlinxSerializer.encodeToString(Base.serializer(), payload) // payloadString1 = "{"@class": "com.example.Base.Child"}"
val payloadString2 = kotlinxSerializer.encodeToString(Base.Child.serializer(), payload) // payloadString2 = "{}"
The problem is, I can’t find a way to force the Ktor client to use the sealed class’s serializer.
Slack Conversation