-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: 4.0.0
-
Component/s: BSON
-
Minor Change
-
Not Needed
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.
- is related to
-
JAVA-4051 BasicDBObject.equals throws exception when one of its fields is a UUID
- Closed