-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Officially support "ndjson" #33
Comments
I may be missing something, but Jackson already supports reading and writing of sequences of white-space separate values, and not just individual value. Reading most conveniently via And writing using There may be room for improved ergonomics of course, with addition of things. |
Reading newline-delimited json to a list can be achieved using the following piece of code:
|
Would you be able to expand on how to do this (this is the first result when searching jackson ndjson ) I've done
and now i have a writer that i can only call write on. which does default comma between each object. what can i do to change this to a newline? |
There is something else going on if comma is being added: default would be single space. Comma would be only used within values output as JSON Arrays. I suspect that you might be assuming that And finally, to change separator from space to linefeed, call objectWriter = objectWriter.withRootValueSeparator("\n"); |
Hey folks, I have an idiosyncratic ndjson stream where lines can be extremely long (>1MB per line) and a lot of the values are numbers, booleans or nulls, not strings... So I really want to avoid creating Strings as long as possible, and to use So far so good, I'm parsing the first line/object without creating megabytes of garbage, but I can't see how to get The data is coming from a transient stream, not a file, so mark/reset or pushback might be problematic. Any tips? Thanks! |
@acruise So I guess I am asking... how are you trying to use it? |
Thanks! What should I expect to see in the token stream for this?
... an |
@acruise Exactly. So,
|
@cowtowncoder thanks! It turns out I wasn't consuming the expected |
@acruise Ah! Yes, and feeding |
While it is possible to massage the object mapper enough to produce newline-delimited json ("ndjson", see http://ndjson.org/), it would be great to have "official" support in Jackson through a module. Reading ndjson into a collection, list or stream would be straightforward as well (e.g. see https://github.com/CjHare/systematic-trading/blob/master/systematic-trading-backtest-output-elastic/src/main/java/com/systematic/trading/backtest/output/elastic/serialize/NdjsonListSerializer.java for a basic example on what a serializer could look like).
The text was updated successfully, but these errors were encountered: