Hi there,
I am currently writing a small web app based on the Takes Framework.
I want to return a JSON response and I noticed that the content of a RsJSON.Source is not correctly written to the ByteArrayOutputStream.
After some testing I found the possible solution:
private static byte[] print(final RsJSON.Source src) throws IOException {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
Json.createWriter(baos).write(src.toJSON());
return baos.toByteArray();
}
must include a call to the JsonWriter.close() to flush the write to the underlying BAOS.
private static byte[] print(final RsJSON.Source src) throws IOException {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
JsonWriter writer = Json.createWriter(baos)
writer.write(src.toJSON());
writer.close()
return baos.toByteArray();
}