Skip to content

Writing custom serializers for Kotlin types in MongoDB and the official Kotlin driver

The official Java & Kotlin drivers provide a CodecRegistry system for registering custom serialization strategies.

KtMongo entirely delegates serialization to the official driver, so it is automatically compatible with your existing configuration.

Learn more in the official driver's documentation:

Warning

If your custom serializer renames fields (serializes fields using another name than written in the Kotlin source code) you must configure KtMongo to be aware of that fact. Otherwise, the generated requests may use incorrect field names. See PropertyNameStrategy.