|
21 | 21 | import org.bson.BsonBinaryWriter;
|
22 | 22 | import org.bson.BsonDocument;
|
23 | 23 | import org.bson.BsonDocumentWrapper;
|
| 24 | +import org.bson.UuidRepresentation; |
24 | 25 | import org.bson.codecs.Decoder;
|
25 | 26 | import org.bson.codecs.DecoderContext;
|
26 | 27 | import org.bson.codecs.Encoder;
|
27 | 28 | import org.bson.codecs.EncoderContext;
|
28 | 29 | import org.bson.codecs.configuration.CodecRegistry;
|
29 | 30 | import org.bson.conversions.Bson;
|
| 31 | +import org.bson.internal.CodecRegistryHelper; |
30 | 32 | import org.bson.io.BasicOutputBuffer;
|
31 | 33 | import org.bson.io.OutputBuffer;
|
32 | 34 | import org.bson.json.JsonMode;
|
@@ -220,10 +222,15 @@ public int hashCode() {
|
220 | 222 | return Arrays.hashCode(toBson(canonicalizeBSONObject(this)));
|
221 | 223 | }
|
222 | 224 |
|
| 225 | + /** |
| 226 | + * Convert the object to its BSON representation, using the {@code STANDARD} representation for UUID. This is safe to do in the context |
| 227 | + * of this class because currently this method is only used for equality and hash code, and is not passed to any other parts of the |
| 228 | + * library. |
| 229 | + */ |
223 | 230 | private static byte[] toBson(final DBObject dbObject) {
|
224 | 231 | OutputBuffer outputBuffer = new BasicOutputBuffer();
|
225 |
| - DBObjectCodec.getDefaultRegistry().get(DBObject.class).encode(new BsonBinaryWriter(outputBuffer), dbObject, |
226 |
| - EncoderContext.builder().build()); |
| 232 | + CodecRegistryHelper.createRegistry(DBObjectCodec.getDefaultRegistry(), UuidRepresentation.STANDARD) |
| 233 | + .get(DBObject.class).encode(new BsonBinaryWriter(outputBuffer), dbObject, EncoderContext.builder().build()); |
227 | 234 | return outputBuffer.toByteArray();
|
228 | 235 | }
|
229 | 236 |
|
|
0 commit comments