kotlinx.serialization with polymorphism: Is there ...
# serialization
a
kotlinx.serialization with polymorphism: Is there any way to affect what type discriminator is used? I can see that we can choose which JSON field is being used for class discrimination, but can’t find a way to affect the actual discriminator used. Ideally i don’t want my clients to have to care about entire package hierarchy. Jackson for instance lets you choose SimpleName instead of full type. e.g instead of
{"#type": "my.app.model.Employee", "name": "John"}
i want something like
{"#type": "Employee", "name": "John"}
Any ideas?
e
you can change using
@SerialName
Copy code
@Serializable
@JsonClassDiscriminator("#type")
sealed class Foo {
    @Serializable
    @SerialName("foo")
    data class Bar(...) : Foo()