Serializer for class 'ObjectId' is not found when pass a data object in a response in Ktor server

Hi everyone,
As described in the title, whether it is a kotlin-driver’s bug or I missed somewhere in my code?



I solved my problem. MongoDB Driver is great. You have a lot of customizations to play around with it.

How did you solve your issue ?

I overrode ObjectId field with Custom Serializers as the attached picture. You can follow document link to get full customization for other types.

1 Like

I went throught the documenrtation.
Got it Thank You.

I am not able to get it working seamlessly with the custom Serializer that i have written, could either you share the Custom serializer for ObjectId

The problem here is kotlinx.serialization doesn’t know BSON types. So, you need to transform these types to JSON types. This is my Custom serializer for ObjectId, as you wish.