Help with org.bson.codecs.configuration.CodecConfigurationException

This is my use case

  1. I have a project with multiple modules. Each module is packages as a jar.
  2. 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.
  3. 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(
    at java.base/java.util.Optional.orElseGet(
    at org.bson.internal.ProvidersCodecRegistry.get(
    at org.bson.internal.ProvidersCodecRegistry.get(
    at com.mongodb.internal.operation.Operations.getCodec(
    at com.mongodb.internal.operation.Operations.bulkWrite(
    at com.mongodb.internal.operation.Operations.insertOne(
    at com.mongodb.internal.operation.SyncOperations.insertOne(
    at com.mongodb.client.internal.MongoCollectionImpl.executeInsertOne(
    at com.mongodb.client.internal.MongoCollectionImpl.insertOne(
    at com.mongodb.client.internal.MongoCollectionImpl.insertOne(
  4. 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?
  5. Isnt there a default codec registry for all all POJOs?

Any help is appreciated

Best REgards