[JAVA-3935] PojoCodecProvider recognition of classes with discriminators only Created: 13/Jan/21 Updated: 05/Feb/21 Resolved: 05/Feb/21 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | POJO |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Alex Bevilacqua | Assignee: | Ross Lawley |
| Resolution: | Duplicate | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Attachments: |
|
||||||||||||
| Issue Links: |
|
||||||||||||
| Case: | (copied to CRM) | ||||||||||||
| Description |
|
A custom Codec or PojoCodec may need to be explicitly configured and registered to handle this type. exception can be raised when a class without properties (discriminator only) is a base class of one class as well as a nominal type in another class. |
| Comments |
| Comment by Ross Lawley [ 05/Feb/21 ] | ||||
|
Hi john.lilley@redpointglobal.com, Thanks for the update. I'll close this ticket out, please follow JAVA-4001 for the fix for automatic / package based PojoCodecs. All the best, Ross | ||||
| Comment by John Lilley [ 05/Feb/21 ] | ||||
|
I have verified that the workaround of useDiscriminator = true does fix the issue. This is the comment left in my support ticket. It may be relevant:
My name is **** and I'll be assisting my colleagues with this case.
The root cause of the exception turns out to have nothing to do with the use of discriminators. Rather, it's that the PojoCodecProvider doesn't recognize classes with no properties as POJOs. Since SettingValue, the base class for SettingValueDashboard and also the nominal type of the value property in the SettingClass, has no properties, no Codec is found for that class and therefore an exception is thrown. To work around this restriction, you can either
| ||||
| Comment by Ross Lawley [ 05/Feb/21 ] | ||||
|
I also added JAVA-4001 - which highlights the issue with automatic / package based PojoCodecs, where ClassModels don't contain any properties. Ross | ||||
| Comment by Ross Lawley [ 05/Feb/21 ] | ||||
|
Hi ross.lawley, When using automatic / package based PojoCodecs can sometimes need help with discriminator lookups. We have JAVA-3707 to improve looking up discriminators. Regarding the scratch repo, the issue in the Setting class @BsonProperty defaults to false for fields using discriminators - enabling it should fix your issue.
Ross | ||||
| Comment by John Lilley [ 13/Jan/21 ] | ||||
|
The attached scratch.zip demonstrates the issue |