[JAVA-4578] Java driver cannot handle Deeper Polymorphic trees Created: 18/Apr/22 Updated: 21/Aug/23 |
|
| Status: | Backlog |
| Project: | Java Driver |
| Component/s: | BSON, Codecs, POJO |
| Affects Version/s: | 4.3.4 |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Greg Stewart | Assignee: | Ross Lawley |
| Resolution: | Unresolved | Votes: | 1 |
| Labels: | external-user | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||
| Epic Link: | Investigate our POJO implementation | ||||||||||||||||
| Quarter: | FY24Q2 | ||||||||||||||||
| Documentation Changes Summary: | 1. What would you like to communicate to the user about this feature? |
||||||||||||||||
| Description |
|
The Pojo codec is limited in handling multiple level generic types that are passed through the class heirarchy. Take the following classes:
The concrete types of GenericPassThroughModelImpl are lost due to the PojoCodecs type detection. See first comment for the previous description. |
| Comments |
| Comment by Greg Stewart [ 07/Oct/22 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hey! Hope things are going well! Was wondering about the status of this, as I end up hitting this issue fairly regularly. I did find somewhat of a workaround though; depending on semantics, you can make the methods of a superclass abstract, then actually add the field of the implementing class and override the required methods there. This enforces the same behavior as before, and lets Mongo make sense of the concrete class, instead of losing that field's type information. Not optimal due to needing to implement more things, but still achieve some of the benefits of inheritance. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Greg Stewart [ 28/Apr/22 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hey Ross, Thanks for taking a look at it, glad to hear it was reproducible! | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Ross Lawley [ 28/Apr/22 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Thank you for the ticket and the code showing the issue. I've simplified the example and updated the description. The improvements required for the PojoCodec to handle this will need to be scheduled and planned as its would require some heavy rewriting of the ClassModel building logic. Ross | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Ross Lawley [ 28/Apr/22 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
*Description was: * Apologies if this isn't quite the avenue for this; I have gone through more 'normal' channels and haven't gotten a response:
SummaryIt seems that the current Java driver (versioned to what is used by current versions of Quarkus) cannot process polymorphic objects deeper than one level:
This is realized as such: (Full code on Github)
TrackedItem is able to be CRUD'ed just fine, but both SimpleAmountItem and ListAmountItem produce the same following error when trying to create:
It appears that Mongo can reconcile direct/first descendants of a superclass, but not if the inheritance tree gets any deeper than that. Is this as designed, a bug, or something I can tweak to get around? It appears to me that Mongo gets stuck on trying to reconcile the Simple/ListAmountItems as a plain AmountItem, which makes sense as why it's failing, but not terribly clear as to how to fix it. The @BsonDiscriminator seems rather simplistic, esp. compared to Jackson. Looks like there might be some support for specifying known types, but I don't see an analogous java annotation: https://mongodb.github.io/mongo-csharp-driver/2.6/reference/bson/mapping/polymorphism/ Please provide the version of the driver. If applicable, please provide the MongoDBorg.mongodb:bson:4.3.2, locked to what is used by Quarkus `2.8.0.Final` How to ReproduceHave a deeper polymorphic tree, attempt to perform a CREATE on the deeper objects. Failing tests on Github Actions: https://github.com/Epic-Breakfast-Productions/OpenQuarterMaster/runs/6064459996#r1s0 My source is on Github: You can run ./gradlew test to run this (in the base station Quarkus server), and see the errors. Note you will need to run ./gradlew publishMavenLocal on the lib project first: https://github.com/Epic-Breakfast-Productions/OpenQuarterMaster/tree/main/software/libs/open-qm-core |