Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-2917

Add BsonBinary helpers to create UUIDs based on different formats

    • Type: Icon: New Feature New Feature
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.9.0
    • Affects Version/s: None
    • Component/s: BSON
    • Labels:
      None

      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.

            Assignee:
            jonathan.ma@mongodb.com Jonathan Ma
            Reporter:
            ross@mongodb.com Ross Lawley
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: