[JAVA-3916] Driver decodes BsonInt64 as Integer Created: 21/Dec/20 Updated: 28/Oct/23 Resolved: 13/Jan/21 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | Scala |
| Affects Version/s: | 4.1.0 |
| Fix Version/s: | 4.2.0 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Andrii Abramov | Assignee: | Ross Lawley |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
``` ``` ``` ``` |
||
| Attachments: |
|
| Description |
|
Driver fails to read `BsonInt64` as Long and results in ClassCastException:
Minimal reproducible example: https://gist.github.com/aaabramov/89625595893d0ff513d1512b43a21caa
What happens here is that driver reads `field` as an `Integer` and puts it into `org.bson.Document#documentAsMap` then tries to class it as a `Long` in `org.bson.Document#getLong`.
And the interesting thing is we'll try to persist `coll.insertOne(Document("field" -> BsonInt64(Long.MaxValue))).toFuture()` everything would work just fine. So seems that driver chooses resulting type based on its value?
It was working fine with driver `"org.mongodb.scala" %% "mongo-scala-driver" % "2.7.0"`
|
| Comments |
| Comment by Githook User [ 13/Jan/21 ] |
|
Author: {'name': 'Ross Lawley', 'email': 'ross.lawley@gmail.com', 'username': 'rozza'}Message: Scala: Ensure implicit conversion keeps type fidelity (#627) When converting from a BsonDocument to org.bson.Document
|
| Comment by Ross Lawley [ 11/Jan/21 ] |
| Comment by Jeffrey Yemin [ 21/Dec/20 ] |
|
Thanks for the bug report. We'll have a look soon and get back to you. Thanks, |
| Comment by Andrii Abramov [ 21/Dec/20 ] |
|
Seems that type is lost during implicit conversion between scala & java `Document` in `org.mongodb.scala#documentToUntypedDocument`. It is implemented with ScalaDocument=>JSON=>JavaDocument conversion and JsonReader decides whether to pick Long or Integer. I would expect the driver to return strict type as it was before. |