NOTE: The problem in this question is the cause of my previous question.
I am generating UUID to bytes of length 16. Then adding it into JsonArray. When I get the first and the only element from JsonArray, .getString(0)
and convert it back to bytes, the length of the resulted bytes is 24.
byte[] uuid = UUIDToolBox.fromUUIDToBytes(UUID.randomUUID());
System.out.println("uuid byteArray = " + Arrays.toString(uuid) + ", length:" + uuid.length );
JsonArray j = new JsonArray().add(uuid);
byte[] n = j.getString(0).getBytes(Charset.forName("UTF-8"));
System.out.println("from String = " + Arrays.toString(n) + ", length:" + n.length);
public static byte[] fromUUIDToBytes(UUID uuid) {
ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
bb.putLong(uuid.getMostSignificantBits());
bb.putLong(uuid.getLeastSignificantBits());
return bb.array();
}
I have tried many conversion charset types, but none worked.