[JAVA-4838] Support using @BsonId with @BsonCreator Created: 12/Jan/23 Updated: 28/Oct/23 Resolved: 27/Jan/23 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | POJO |
| Affects Version/s: | None |
| Fix Version/s: | 4.9.0 |
| Type: | Improvement | Priority: | Unknown |
| Reporter: | Ross Lawley | Assignee: | Ross Lawley |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||
| Documentation Changes: | Needed | ||||||||||||
| Documentation Changes Summary: | We need to mention this change in What's new. |
||||||||||||
| Description |
|
The annotation convention uses @BsonProperty("field") value to either look up the field mapping in the ClassModel or creates a new one PropertyModel. However, special handling for @BsonId fields means that if the _id field property is missing in the ClassModel then it throw an NPE error.
I opted against allowing the following model to be able to decode from MongoDB:
Test case:
The reason being supporting the @BsonId in the constructor would make the ClassModel asymmetrical and that is non-obvious. It would encode differently to decoding. So opted for a clearer error message instead. This helps the user to correct the issue with the model and help the PojoCodec decide the right cause of action. |
| Comments |
| Comment by Githook User [ 27/Jan/23 ] |
|
Author: {'name': 'Ross Lawley', 'email': 'ross.lawley@gmail.com', 'username': 'rozza'}Message: PojoCodec BsonId error message (#1071) Help users when using a BsonId in a constructor and there is no
|