[JAVA-3825] Bson Filter behavior differs from BasicDBObject Filter Created: 28/Aug/20 Updated: 01/Sep/20 Resolved: 31/Aug/20 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | Codecs, Query Operations |
| Affects Version/s: | 3.12.5 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Barron Anderson | Assignee: | Brian DeLeonardis (Inactive) |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
MacOS Mojave 10.14.6, Java 1.8, Driver 3.12.5, Mongo 3.6.17-ent single node replicaset |
||
| Description |
|
Working with customer to upgrade a data access layer Java class. Trying to implement consistency across the board. I have elected to use the Bson query helpers defined in "org.bson.conversions.Bson.Filters". I am converting use of BasicDBObject and encountered a difference. For this reason I am creating this ticket. This might be a known behavior or might be a discovered bug - I will let you decide! Here are the details...
Consider the following unit test...
If I change the filter predicate to use the Filters helper Bson object..
{{ I get a codec error org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class [Ljava.lang.Integer;.}}
Please advise... |
| Comments |
| Comment by Barron Anderson [ 01/Sep/20 ] | ||
|
Thanks for the clarification Brian. Regarding the overloads... Are you saying because this example uses a variable of type Object it uses the method signature ...
... whereas if it were Integer[] it would use ....
? | ||
| Comment by Brian DeLeonardis (Inactive) [ 31/Aug/20 ] | ||
|
Hi @ BarronAnderson, You can also pass in a list: nin("fieldname", Arrays.asList(4, 5, 6)) because the nin method is overloaded so it will go to the method with the: public static <TItem> Bson nin(final String fieldName, final Iterable<TItem> values) signature. In your second example’s case, the problem is that the second parameter has a static type of Object (not an array), so the compiler is putting the entire array into one parameter in the nin function. If you change the static type of your variable value to Integer[] it should work. |