[JAVA-2917] Add BsonBinary helpers to create UUIDs based on different formats Created: 27/Jul/18  Updated: 28/Oct/23  Resolved: 11/Sep/18

Status: Closed
Project: Java Driver
Component/s: BSON
Affects Version/s: None
Fix Version/s: 3.9.0

Type: New Feature Priority: Major - P3
Reporter: Ross Lawley Assignee: Jonathan Ma
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
Case:

 Description   

Enhance the org.bson.types.Binary and org.bson.BsonBinary class to allow instances to be created from a UUID and to convert instances to a UUID, supporting all the formats enumerated in the UuidRepresentation enum. This approach negates the need for manipulating the CodecRegistry to handle {{UUID}}s and treats them just as binary blobs.

The API for BsonBinary will be something like this:

    /**
     * Create a Type 4 BsonBinary from the given UUID
     */
    public BsonBinary(final UUID uuid) {//...}
 
    /**
     * Create BsonBinary from the given UUID and representation
     */
    public BsonBinary(final UUID uuid, final UuidRepresentation uuidRepresentation) {// ...}
 
    /**
     * Return the binary as a UUID.  The binary type must be 4.
     */
    public UUID asUuid() {// ...}
 
    /**
     * Return the binary as a UUID.  The binary type must match what is required by the given UUID representation.
     */
    public UUID asUuid(final UuidRepresentation uuidRepresentation) {// ...}

The API for Binary will be similar.

The code to implement this already exists in org.bson.codecs.UuidCodec but will need to be refactored to avoid code duplication.



 Comments   
Comment by Githook User [ 11/Sep/18 ]

Author:

{'name': 'Jonathan', 'email': 'thejonathanma@gmail.com', 'username': 'thejonathanma'}

Message: Allow BsonBinary to be created from UUIDs

This commit enhances the BsonBinary class to allow instances to be
created from a UUID and to convert instances to a UUID. There is a
bit of refactoring since a lot of the code for the encode and
decode methods in UuidCodec could be reused for this.

JAVA-2917
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/629dad944e1f35649fd0cc0d2cfd930ba745d44a

Generated at Thu Feb 08 08:58:22 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.