public static byte[] toByteArray(Document document, JsonFormat.EncodeOptions tensorOptions) {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        JsonWriter writer = new JsonWriter(out, tensorOptions);
        writer.write(document);
        return out.toByteArray();
    }
Utility method to easily serialize a single document.

@param document the document to be serialized
@param tensorOptions tensor formatting options (short/long, direct/wrapped, hexdump or not)
@return the input document serialised as UTF-8 encoded JSON
document/src/main/java/com/yahoo/document/json/JsonWriter.java