```interface Animal @Serializable class Dog : Ani...
# ktor
d
Copy code
interface Animal

@Serializable
class Dog : Animal

@Serializable
class Cat : Animal

// subclasses are explicitly registered in serializerModule.

client.get<...>("...") {
    contentType(Json)
    body = Dog()
}
How do I get ktor to do polymorphic serialisation correctly?
body
ends up being
{}
instead of
{ "type": "Dog" }
.
b
I think you need sealed classes for that
Also @Serializable
d
I do have
@Serializable
, was just impatient when writing the code lol.
b
But not sealed classes. Last I checked polymorphism was only supported on sealed hierarchies
d
It's supported everywhere now. Unless you're talking about ktor.
b
No, I was talking about serialisation itself. Good to know then and I'm out of my depth here 😀
d
Haha, thanks for trying though. Looks like a bug in ktor.
a
moko-network support allOf,anyOf,oneOf and it implemented with generation of special serializers, like this - https://github.com/icerockdev/moko-network/blob/master/network/src/commonTest/kotlin/OneOfTest.kt#L122