Details
-
Bug
-
Resolution: Fixed
-
Major - P3
-
4.0.0
-
Minor Change
-
Not Needed
Description
Consider this code:
var uuid = UUID.randomUUID()
|
var dbo1 = new BasicDBObject("_id", uuid); |
|
dbo1.toString()
|
In the 3.x driver this will print the dbo, but in 4.x it will throw:
Exception in thread "main" org.bson.codecs.configuration.CodecConfigurationException: |
The uuidRepresentation has not been specified, so the UUID cannot be encoded.
|
at org.bson.codecs.UuidCodec.encode(UuidCodec.java:72) |
at org.bson.codecs.UuidCodec.encode(UuidCodec.java:37) |
at org.bson.codecs.EncoderContext.encodeWithChildContext(EncoderContext.java:91) |
at com.mongodb.DBObjectCodec.writeValue(DBObjectCodec.java:246) |
at com.mongodb.DBObjectCodec.encode(DBObjectCodec.java:159) |
at com.mongodb.DBObjectCodec.encode(DBObjectCodec.java:67) |
at com.mongodb.BasicDBObject.toBson(BasicDBObject.java:225) |
at com.mongodb.BasicDBObject.equals(BasicDBObject.java:21 |
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.
Attachments
Issue Links
- is related to
-
JAVA-4051 BasicDBObject.equals throws exception when one of its fields is a UUID
-
- Closed
-