___type field added when custom SerialDescriptor is used

22 views
Skip to first unread message

nac

unread,
Mar 30, 2023, 3:27:38 AM3/30/23
to kmongo
When I use custom SerialDescriptor like below

    override val descriptor: SerialDescriptor = SerialDescriptor("PetDboCustomSerializer", PetDboSurrogate.serializer().descriptor)

a ___type field is assigned to the document and saved to collection. This field is not assigned when I use kotlinx 1.3.3.

Is it some known behavior?
Is it kotlinx or kbson or kmongo fault?

Used versions:
org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.0
kmongo: 4.6.0

nac

unread,
Mar 30, 2023, 9:31:27 AM3/30/23
to kmongo
I found that it's part of Kbson.
    val classDiscriminator: String = "___type"

Can I somehow disable this behavior?

nac

unread,
Mar 31, 2023, 10:12:16 AM3/31/23
to kmongo
This behavior was caused by sealed interface which I was using. After changing it to regular interface it works as expected.
This thread can be closed.
Reply all
Reply to author
Forward
0 new messages