Skip to content

RSJson must close the JsonWriter to flush it's content into the ByteArrayOutputStream #346

@GilraenBurland

Description

@GilraenBurland

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();
}

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions