[JAVA-3769] Allow multiple POJO codec providers Created: 19/Jun/20  Updated: 28/Oct/23  Resolved: 09/Oct/20

Status: Closed
Project: Java Driver
Component/s: POJO
Affects Version/s: None
Fix Version/s: 4.2.0

Type: Improvement Priority: Minor - P4
Reporter: Sheila Doyle Assignee: Brian DeLeonardis (Inactive)
Resolution: Fixed Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Zip Archive scratch (1).zip    
Case:

 Description   

Updated Description

Enhance the PojoCodeProvider such that multiple instance can be added to the same registry and POJO codecs can be looked up between the providers.

Original Description

Using multiple codec providers sometimes causes a problem with a failure to find the 'log_entry' discriminator.

It appears that loading the same set of providers does not cause a failure if loaded in a different order.

e.g the following code causes a failure

 
{
    
 
		CodecRegistry pojoCodecRegistry = CodecRegistries.fromRegistries(
				CodecRegistries.fromCodecs(new UuidCodec(UuidRepresentation.STANDARD)), 
				CodecRegistries.fromProviders(_getCodecProvider1(), _getCodecProvider2()),
//				CodecRegistries.fromProviders(_getCodecProvider()),
				MongoClientSettings.getDefaultCodecRegistry());
 
}

However replacing the line to load the codeC provider with :

 
{
CodecRegistries.fromProviders(_getCodecProvider(),_getCodecProvider1(),_getCodecProvider2()),
}

or this

 
{
 
CodecRegistries.fromProviders(_getCodecProvider()),
				MongoClientSettings.getDefaultCodecRegistry());
 
}

does not cause a failure.

So it appears that the issue is related to :

1. Allowing more than 1 provider.
2. The order in which the providers are loaded.

Please advise.

Best regards,

Sheila



 Comments   
Comment by Githook User [ 09/Oct/20 ]

Author:

{'name': 'Brian DeLeonardis', 'email': 'bdeleonardis1@gmail.com', 'username': 'bdeleonardis1'}

Message: Fix discriminator lookup bug for multiple PojoCodecProviders

JAVA-3769
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/dc9d65fea146740c4ca32a2ee5f8cdf4f43e3be1

Comment by Ross Lawley [ 30/Jun/20 ]

I think there is some work that could be done to improve the discriminator lookup / or the error messaging for this scenario.

Until then, the work around is to use a single PojoCodecProvider for any Pojo classes.

Comment by Sheila Doyle [ 24/Jun/20 ]

jeff.yemin I initially intended this to be a Java ticket, but please let me know if it should be moved back to a HELP ticket.

Requested information from customer.

Comment by Jeffrey Yemin [ 19/Jun/20 ]

Hi sheila.doyle

To progress this case, please provide the following information:

  1. The code for _getCodecProvider1,  _getCodecProvider2, and  _getCodecProvider
  2. Why they need more than one codec provider. It's not a scenario we have anticipated, though I don't see immediately why it would not work.
  3. The stack trace for the failure.
  4. Any other relevant application code, e.g. the POJO classes themselves

ross.lawley if you can think of anything else, please add.
 

 

Generated at Thu Feb 08 09:00:23 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.