[JAVA-3902] POJO mapping - Setter can't be found if property is capitalized like xAxis Created: 08/Dec/20 Updated: 10/Oct/22 |
|
| Status: | Backlog |
| Project: | Java Driver |
| Component/s: | POJO |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Minor - P4 |
| Reporter: | Maxime Beugnet | Assignee: | Unassigned |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
A user reached out to me because his piece of code wasn't working as expected. https://gist.github.com/pavangayakwad/5adbece8e11b26508a1338dc032c60ae He had a POJO with a few fields and 2 of them were named "xAxisColumn" and "yAxisColumn". All the fields were mapped correctly - he could write them to MDB but not retrieve these 2. His IDE and mine (IntelliJ) generated the getter and setter like so: getxAxisColumn and setxAxisColumn (note the lower case X). And we are expecting getXAxisColumn (upper case X) apparently which respect the CamelCase - but apparently this is not the correct answer as it's not respecting the JavaBeans API specification from 1997 This isn't a big deal per say - and there is an easy workaround. But this is really confusing and not an easy bug to find / understand as it's based on introspection if I understand this correctly. Here is a piece of code to illustrate better what I'm saying.
Ouput:
|
| Comments |
| Comment by Ross Lawley [ 09/Dec/20 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The logic for determining getters is as follows:
That means getxAxis is never considered to be a getter, this would force the user to manually add a propertyModel for xAxis. There would also be a conflict as the default naming system maps getXAxis to xAxis. While it is a contrived edge case having two conflicting properties like this and ultimately, the PojoCodec can support that. It does however, require user intervention and a good knowledge of how to build a PojoCodec for a class to be able achieve that. So there are two things to consider: 1) Adding support for getters/setters like getxAxis() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Maxime Beugnet [ 08/Dec/20 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I had a typo in my comment above. I fixed it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Ross Lawley [ 08/Dec/20 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Thats a fun example! The PojoCodec by default relies on the camelCase convention, this means properties / methods start with a lower cased letter. So getPropertyName() maps to propertyName. The above case with both getxAxis() and getXAxis() isn't unexpected - it follows the above convention. Without further configuration the PojoCodec only sees the getXAxis() method and maps that to a xAxis property. The method getxAxis() is totally ignored by the PojoCodec as are any other non conventionally named methods. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Maxime Beugnet [ 08/Dec/20 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
EDIT: I had a typo in it. I fixed it. This example is even more problematic I think:
Ouput:
In the collection:
Definitely surprising for someone unaware of this edge case.
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Jeffrey Yemin [ 08/Dec/20 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Thanks for the report. We'll have a look and see if there's anything we can do. |