Hi all, does anyone know how to make a `JsonConfig...
# serialization
t
Hi all, does anyone know how to make a
JsonConfiguration(classDiscriminator = "customType")
work only for a particular class? For instance, let’s say I have something like:
Copy code
@Serializable
data class MyClass(
  @Polymorphic
  val polymorphicA: PolymorphicA,
  @Polymorphic
  val polymorphicB: PolymorphicB
)
And I’m serializing/deserializing an instance of
MyClass
. I want to serialize/deserialize
polymorphicA
using the default
classDiscriminator
which is
type
. However, I want to serialize/deserialize
polymorphicB
using a custom
classDiscriminator
, say
customType
. I don’t think the steps outlined in https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/polymorphism.md#a-bit-of-customizing showcase that level of granularity (i.e. if a custom
classDiscriminator
is specified, it’s applied to all of
MyClass
, which is not what I want).
My current work-around is a custom serializer.
t
Ah, this is helpful. Thanks.