Hi! I’m encountering a very strange behaviour when...
# serialization
f
Hi! I’m encountering a very strange behaviour when using the Ktor JS client with
JsonFeature
. I have the following class structure:
Copy code
@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:
Copy code
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