Sending a byte array in json using jackson

If you are using Jackson for JSON parsing, it can automatically convert byte[] to/from Base64 encoded Strings via data-binding.

Or, if you want low-level access, both JsonParser and JsonGenerator have binary access methods (writeBinary, readBinary) to do the same at level of JSON token stream.

For automatic approach, consider POJO like:

public class Message {
  public String mimetype;
  public byte[] value;
}

and to create JSON, you could do:

Message msg = ...;
String jsonStr = new ObjectMapper().writeValueAsString(msg);

or, more commonly would write it out with:

OutputStream out = ...;
new ObjectMapper().writeValue(out, msg);

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)