[JAVA-4140] BasicDBObject/Document toString methods throw exceptions when one of the fields is a UUID Created: 05/May/21 Updated: 28/Oct/23 Resolved: 15/Jun/21 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | BSON |
| Affects Version/s: | 4.0.0 |
| Fix Version/s: | 4.3.0 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Yannick Gladow | Assignee: | Jeffrey Yemin |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | external-user | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Backwards Compatibility: | Minor Change | ||||||||
| Documentation Changes: | Not Needed | ||||||||
| Description |
|
Consider this code:
In the 3.x driver this will print the dbo, but in 4.x it will throw:
This is a breaking change. There are workarounds, first rendering toJson with a specific encoder or creating the bson with a UUID representation, but still tricky. Would be great if toString and toJson could work right out of the box. |
| Comments |
| Comment by Githook User [ 15/Jun/21 ] |
|
Author: {'name': 'Jeff Yemin', 'email': 'jeff.yemin@mongodb.com', 'username': 'jyemin'}Message: Use standard UUID representation for JSON generation (#730) Change the behavior of the following methods:
to use standard UUID representation when generating JSON. Prior to this change,
|
| Comment by Jeffrey Yemin [ 14/Jun/21 ] |
|
FYI, my plan is to render UUIDs as BSON binary, type 4 (Standard representation). We have to choose a representation, since we don't have access to MongoClientSettings to tell us what the application expects. By using type 4, at least it's unambiguous what the UUID actually is, even if applications may end up storing the UUID in MongoDB with a different UUID representation. |
| Comment by Jeffrey Yemin [ 10/May/21 ] |
|
We plan to address this in the 4.3.0 release, coming in the next few months. |
| Comment by Yannick Gladow [ 10/May/21 ] |
|
Hey, we are using `toString` in production in some log statements. Unfortunately I can not even grep for all the places where it is used. |
| Comment by Jeffrey Yemin [ 10/May/21 ] |
|
yannick.gladow@commercetools.com, are you using the toString method in production, or is it only test code? |
| Comment by Yannick Gladow [ 10/May/21 ] |
|
Okay great, this is hopefully the last major blocker for us updating to 4.x.x. Thanks! |
| Comment by Esha Bhargava [ 07/May/21 ] |
|
yannick.gladow@commercetools.com Thanks for reporting this issue! We'll look into it soon and get back to you. |