Is it possible to specify a custom class discrimin...
# serialization
a
Is it possible to specify a custom class discriminator for polymorphic deserialisation or does it always have to be
type
?
Copy code
val format = Json { classDiscriminator = "#class" }
a
thanks, that looks straightforward enough, struggling with Retrofit integration though
p
It seems to still be missing from the docs, but kotlinx-serialization 1.3.0 adds
@JsonClassDiscriminator
which lets you specify a 'local' class discriminator, instead of a global one: https://github.com/Kotlin/kotlinx.serialization/pull/1608
🙏 2
🙏 2
s
Oh, that's hype! Thanks!
a
Exactly what I needed, I need to reuse the
Json
instance, I don't have any control over that with retrofit unless I have multiple Retrofit instances