Support BsonCreator with BsonProperty renaming#413
Support BsonCreator with BsonProperty renaming#413visualage wants to merge 6 commits intomongodb:masterfrom
Conversation
This would prefer the new way, then falls back to the legacy lookup.
|
Hi @visualage, Thanks for the ticket. I've added JAVA-2599 to track this issue. A property has 3 names:
This allows for a high level of flexibility over how data is controlled. Currently, in the context of On reflection using the write name would have been a better choice and I like your backwards compatible approach, so thanks again for the patch. We'll look to incorporate into the next release. In the meantime, you can provide your own Ross |
|
Thanks @visualage after rebasing and some minor changes - your PR was commited to master: b376aa4 Thank you for the excellent PR and your work on improving the PojoCodec. |
The existing POJO codec does not work if a property is renamed using @BsonProperty("newName") on the property getter and a @BsonCreator with property @BsonProperty annotations to the parameter.
Also added support of @BsonId annotation to the @BsonCreator's parameter.
To my opinion, the value of @BsonProperty should be mapped to the property name in BSON, regardless where it is annotated. Right now, @BsonProperty value on a @BsonCreator maps to a property getter name. For example, if there is a getter @BsonId getPersonId(), the corresponding constructor parameter annotation should be @BsonId or @BsonProperty("_id) (since '_id' is the property name in BSON), not @BsonProperty("personId") ('personId' does not exist in BSON data). This patch corrects the behavior, but falls back to the old behavior if the new behavior cannot find the right property.