Skip to content

Support for reading line-wise json #1304

Closed
@CodingFabian

Description

@CodingFabian

I am in the process of reducing garbage my application creates, and I found a place where I think I could use jackson but either this is not possible or I could not find the documentation.

I have an input stream which I read line wise. Each line contains a json object I would like to parse.
Right now I need to use a BufferedReader, call readLine and then pass the String to ObjectMapper.readTree().

Now this is bad, because it creates multiple temporary copies in memory (the buffered reader already creates garbage, the temporary string and the IOContext buffer again)
Now I could use jacksons readTree and supply an InputStream.
But This would try to read the stream fully and produce a single tree.
I would love to stop at special markers (in my case linebreaks) and resume reading.

I considered wrapping my stream and emulating line breaks with end-of-file, but I could not find the place in jackson where the end of stream is detected to fake this.

Would you think this is a viable solution (including a hint how to properly fake end of input) or could this be worth adding to jackson

or maybe this already exists?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions