[JAVA-4669] BSON Ignore in POJO Codec not working as expected on methods Created: 05/Jul/22 Updated: 27/Oct/23 Resolved: 21/Jul/22 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | Codecs |
| Affects Version/s: | 4.6.1 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Minor - P4 |
| Reporter: | Dennis Lee | Assignee: | Ross Lawley |
| Resolution: | Works as Designed | Votes: | 1 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Description |
SummaryWhen using codecs with a POJO, any extra methods beginning with the keyword get or set will trigger exceptions, even if the method is marked with the @BsonIgnore annotation. Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).4.6.1 How to ReproduceSteps to reproduce. If possible, please include a Short, Self Contained, Correct (Compilable), Example. public class User { @BsonIgnore
Additional BackgroundPlease provide any additional background information that may be helpful in diagnosing the bug. |
| Comments |
| Comment by Ross Lawley [ 21/Jul/22 ] | ||||||
|
Hi dennis@nornir.io, Not sure I follow - the exceptions I think you're seeing is because the POJO has incompatible types for the mongoID property and the PojoCodec doesn't support overloads for properties. It looks like you want to use the mongoID property as the _id as it has a @bsonId annotation. But you also declare you want to ignore the mongoID property because a setter for it has the @bsonIgnore annotation, which isn't supported (as overloads aren't supported at this time). So the work around would be either to: Use the ObjectId constructor and have a single setter, create an alternative setter and ignore that or create a custom codec. Ross | ||||||
| Comment by Dennis Lee [ 21/Jul/22 ] | ||||||
|
Hi Ross, Wait, so the solution to being able to have more get and set methods in the POJO is to fill it with unused junk variables? | ||||||
| Comment by Ross Lawley [ 21/Jul/22 ] | ||||||
|
Hi dennis@nornir.io, The annotations such as BsonIgnore are used as part of a conventions and are processed after the initial building of the PropertyModel. Please note: BsonIgnore is used to ignore a whole property - which in the above case would be mapped to mongoId. My suggestions would be to add a new property eg setMongoIDFromString and ignore the alternative property. maxsimusi1993@gmail.com those errors can be related to something else and can often be fixed by explicitly configuring a PojoCodec. Ross | ||||||
| Comment by Maxim Fenixov [ 21/Jul/22 ] | ||||||
|
Can confirm for 4.6.1 and 3.12.11, it usually leads to the exception like:
|