kmongo icon indicating copy to clipboard operation
kmongo copied to clipboard

Jackson serializaition module uses global mutable variables

Open caeus opened this issue 3 years ago • 3 comments

It is known global mutable variables are the root of all evil.

Also, my project uses two different CodecRegistries, so it basically uses different serialization configurations, and the fact that the bson mapper used by kmongo is global, ruins adoption for me. (https://github.com/Litote/kmongo/blob/master/kmongo-jackson-mapping/src/main/kotlin/org/litote/kmongo/util/KMongoConfiguration.kt) Can we make this a class, instead of an global object?

caeus avatar Aug 19 '22 21:08 caeus

The issue is that KMongo provides stateless methods like .json or .bson with no relation with MongoClient instance.

So allowing to provide different configurations for a same java runtime would be error prone.

What is the use case for which you need to use two different CodecRegistries at the same time ?

zigzago avatar Aug 20 '22 19:08 zigzago

Moving out of legacy mongo stuff. We cannot just change it all... So we want to give support with the old CodecRegistry, but in use a new CodecRegistry in the new collections

caeus avatar Aug 22 '22 14:08 caeus

In java driver, CodecRegistry can be Collection scoped, Database scoped or Client scoped. It should be doable to pass a configuration for each of this class.

If you "legacy stuff" is not powered by KMongo, you have the option to set manually an old CodecRegistry.

zigzago avatar Sep 07 '22 19:09 zigzago