How to explicitly configure Custom Codec or PojoCodec when AutomaticPojoCodec is giving error?

Hi,

I’m attempting to store an object in a MongoDB database (using MongoDB 3.12.6) and am getting following error:

“org.bson.codecs.configuration.CodecConfigurationException: An exception occurred when encoding using the AutomaticPojoCodec.”

I am using the following lines of code currently to create CodeRegistry:

CodecRegistry codecRegistry = CodecRegistries.fromRegistries(
MongoClientSettings.getDefaultCodecRegistry(),
CodecRegistries.fromProviders(PojoCodecProvider.builder().automatic(true).build()));

But for some reason AutomaticPojoCodec generated here does not seem to work to encode/decode POJO.

Anyone could please suggest on this ?

Hi jutin_george,

Can you provide the complete error trace?

I stumbled upon a similar error but in my case, I am not able to encode BigInteger (which is expected). Apart from that, I believe AutomaticPojoCodec seems to work fine for me.

For me AutomaticPojoCodec is not working for Currency(java.util.Currency).