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.