Hello,
I have a byte[] of a text. How can I write (incl. escaping) this to a JsonGenerator. JsonGenerator#writeRawUTF8String(byte[] buffer, int offset, int length) does the job, but misses escaping.
To provide further background, I am trying to serialize a stack trace to text. But while doing so, I am using a pool of byte[] to avoid allocation. That is,
public void resolve(Throwable throwable, JsonGenerator jsonGenerator) throws Exception {
ByteBufferOutputStream outputStream = outputStreamPool.acquire();
try (PrintStream printStream = new PrintStream(outputStream, false, "UTF-8")) {
exception.printStackTrace(printStream);
}
ByteBuffer outputStreamBuffer = outputStream.getByteBuffer();
jsonGenerator.writeRawUTF8String(outputStreamBuffer.array(), 0, outputStreamBuffer.position());
outputStreamPool.release(outputStream);
}
I will appreciate any tips.
Thanks in advance.
Best.