Is it possible to NOT serialize the class descriminator in JSON ?
s
Is it possible to NOT serialize the class descriminator in JSON ?
c
The class descriminator is only added when it's a sealed class/interface, right? How would you expect to deserialize a polymorphic value without a descriminator?
If your problem is that you don't like what the value is, you can overwrite it using
@SerialName
:
Copy code
@Serializable
sealed class Foo {

    @Serializable
    @SerialName("bar")
    data class Bar(…) : Foo()
}
s
No. I have an example of just a plain nested data class that gets type field. Also I see "type":"kotlin.collections.ArrayList" for lists.
c
Weird. To clarify, we're both talking about KotlinX.Serialization, right?
s
yes
c
I've never seen a class descriminator added for ArrayList
What's your object looking like?
s
Let me reduce it a bit
c
Are you using the default`@Serializable` or is it a custom-made serializer?
s
Almost. It looks like it is triggered by the class having a field with a type that is configured to be
polymophic
in the
serializersModule
.
Looks like I can skip the
type
field with
JsonContentPolymorphicSerializer
which we do not use for this case but probably should.
Copy code
It is possible to serialize values this serializer. In that case, class discriminator property won't be added to JSON stream [...]
c
Why did you configure
ArrayList
to be polymorphic?
s
Where did I do that ?
c
You said:
it is triggered by the class having a field with a type that is configured to be
polymophic
in the
serializersModule
s
I didnt. Look at the bug report for what I do. Its clearly a bug