You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What is your use-case and why do you need this feature?
I am using kotlinx.serialization to consume a JSON document from a third party (in particular I am parsing an OpenAPI Document). As such I cannot change the format of the JSON.
At various places in the specification, a polymorphic discriminator is used (such as in for parameters or type for security schemes). Even though the polymorphic serializer is perfectly capable of deserializing these types on their own, it is impossible to deserialize a document containing them both, because the discriminator property name is configured globally.
As such a completely custom deserializer must be used. PolymorphicSerializer cannot be subclassed and even subclassing the internal AbstractPolymorphicSerializer will not work because StreamingJsonDecoder will just ignore you and completely bypass the AbstractPolymorphicSerializer (see Polymorphic.kt).
To be honest, I find it perplexing that it is possible to override the discriminator property name on a global level at all - the Json serializer has no business in deciding what this property should be called, it depends on the actual type being serialized.
Describe the solution you'd like
I would like an annotation similar to @SerialName which can be used on a class to set the discriminator property name used for its children.
What is your use-case and why do you need this feature?
I am using
kotlinx.serialization
to consume a JSON document from a third party (in particular I am parsing an OpenAPI Document). As such I cannot change the format of the JSON.At various places in the specification, a polymorphic discriminator is used (such as
in
for parameters ortype
for security schemes). Even though the polymorphic serializer is perfectly capable of deserializing these types on their own, it is impossible to deserialize a document containing them both, because the discriminator property name is configured globally.As such a completely custom deserializer must be used.
PolymorphicSerializer
cannot be subclassed and even subclassing the internalAbstractPolymorphicSerializer
will not work becauseStreamingJsonDecoder
will just ignore you and completely bypass theAbstractPolymorphicSerializer
(seePolymorphic.kt
).To be honest, I find it perplexing that it is possible to override the discriminator property name on a global level at all - the Json serializer has no business in deciding what this property should be called, it depends on the actual type being serialized.
Describe the solution you'd like
I would like an annotation similar to
@SerialName
which can be used on a class to set the discriminator property name used for its children.Should produce JSON as follows:
The text was updated successfully, but these errors were encountered: