https://kotlinlang.org logo
#kmongo
Title
# kmongo
t

Tomas Kormanak

10/05/2023, 1:50 PM
Hi, I am working on migration from KMongo to MongoDb Kotlin driver and we would like to keep using kmongo-id for now. But I can't find a way how to setup serializers within the driver and I am getting this error:
Copy code
Class 'StringId' is not registered for polymorphic serialization in the scope of 'Id'
Any idea?
g

Giuliopime

10/13/2023, 9:00 AM
How did you register the Id serializer in the mongo client?
t

Tomas Kormanak

10/13/2023, 9:05 AM
I use this:
Copy code
val idCodec = KotlinSerializerCodec.create(
    Id::class,
    serializersModule = IdKotlinXSerializationModule
)

val registry = CodecRegistries.fromRegistries(
    CodecRegistries.fromCodecs(idCodec), MongoClientSettings.getDefaultCodecRegistry()
)

val settings = MongoClientSettings.builder()
    .applyConnectionString(ConnectionString(config.getTyped("database.url")))
    .codecRegistry(registry)
    .retryWrites(true)
    .build()

val mongoClient = MongoClient.create(settings)
But I found
KotlinSerializerCodec.create
returns null
6 Views