C# encoded UUID as LUUID to java UUID

381 views
Skip to first unread message

Jack Viers

unread,
Dec 8, 2015, 1:40:27 PM12/8/15
to ReactiveMongo - http://reactivemongo.org
I have a series of documents in an existing mongo database. They have UUIDS encoded and written by a c# driver. I don't control the writing of the database. The field is:

(id,BSONBinary(reactivemongo.core.netty.ChannelBufferReadableBuffer@73e5d86f,OldUuidSubtype))

How can I convert this properly into a java UUID?

I have tried wrapping the binary byte array in a buffer, changing the endian-ness, and reading two longs. I have tried 
nameUUIDFromBytes.

In the db, the value prints as LUUID("b4756f84-b332-794d-836d-35f97aed7336"). However, once I create a UUID from the two longs or the nameUUIDFromBytes I don't get this value inside of the java UUID.

Jack Viers

unread,
Dec 8, 2015, 1:56:51 PM12/8/15
to ReactiveMongo - http://reactivemongo.org
Solution discovered:

You have to switch endian-ness on the entire byte array:

def read(b: BSONBinary) = {
        val bb = ByteBuffer.wrap(ByteBuffer.wrap(b.byteArray).order(ByteOrder.LITTLE_ENDIAN).array())
        val (fst, snd) = (bb.getLong, bb.getLong)
        new UUID(fst, snd)
      }
Reply all
Reply to author
Forward
0 new messages