The typical way to send binary in json is to base64 encode it.
Java provides different ways to Base64 encode and decode a byte[]
. One of these is DatatypeConverter
.
Very simply
byte[] originalBytes = new byte[] { 1, 2, 3, 4, 5};
String base64Encoded = DatatypeConverter.printBase64Binary(originalBytes);
byte[] base64Decoded = DatatypeConverter.parseBase64Binary(base64Encoded);
You'll have to make this conversion depending on the json parser/generator library you use.