This is my use case
- I have a project with multiple modules. Each module is packages as a jar.
- I have a Module A, whcih has all the utility functions to read, write to MongoDB. The idea is any module which wants to read and write , uses this module.
- The other modules like ModuleB, which have POJOs to be written and read defined in them. When i try to write a POJO defined in ModuleB using mongodb read and write wrappers defined in ModuleA, I get the following exception
org.bson.codecs.configuration.CodecConfigurationException: Can’t find a codec for CodecCacheKey{clazz=class MyClass, types=null}.
at org.bson.internal.ProvidersCodecRegistry.lambda$get$0(ProvidersCodecRegistry.java:84)
at java.base/java.util.Optional.orElseGet(Optional.java:369)
at org.bson.internal.ProvidersCodecRegistry.get(ProvidersCodecRegistry.java:74)
at org.bson.internal.ProvidersCodecRegistry.get(ProvidersCodecRegistry.java:48)
at com.mongodb.internal.operation.Operations.getCodec(Operations.java:709)
at com.mongodb.internal.operation.Operations.bulkWrite(Operations.java:464)
at com.mongodb.internal.operation.Operations.insertOne(Operations.java:390)
at com.mongodb.internal.operation.SyncOperations.insertOne(SyncOperations.java:176)
at com.mongodb.client.internal.MongoCollectionImpl.executeInsertOne(MongoCollectionImpl.java:475)
at com.mongodb.client.internal.MongoCollectionImpl.insertOne(MongoCollectionImpl.java:458)
at com.mongodb.client.internal.MongoCollectionImpl.insertOne(MongoCollectionImpl.java:452) - The reason might be that the codec registry has to defined in ModuleA, when we create a MongoClient?
i want a scenario, where the consumers of the MogoClient decide the codecREgisrtey and not at the time of client creation.
Can each cosumer add its own classes to the CodecREgistry? - Isnt there a default codec registry for all all POJOs?
Any help is appreciated
Best REgards
Ani