FasterXML / jackson-core

Core part of Jackson that defines Streaming API as well as basic shared abstractions
Apache License 2.0
2.25k stars 773 forks source link

Add new method like `JsonParser.readText(Writer)` (and implementation) for truly non-buffering reads #1288

Open cowtowncoder opened 4 months ago

cowtowncoder commented 4 months ago

(note: off-shoot of https://github.com/FasterXML/jackson/discussions/221) (note: was earlier filed as #15, mea culpa)

Currently there is no way to access contents of long JSON String values without buffering of all contents in memory: even metho

JsonParser.getText(Writer)

will temporarily buffer contents in TextBuffer (but avoids construction of big String unlike getText()). But it would be possible and desirable to have an alternative that would decode and provide content without buffering; similar to how Stax2-compliant XML parsers (Aalto, Woodstox) do it.

Semantic difference would be that such method, f.ex

JsonParser.readText(Writer)

would read, pass and consume contents, such that after call finishes, parser now points to the end of text value, and text value could no longer be read. Because of this change, we cannot change implementation of existing getText(Writer)

I will also update Javadocs of getText(Writer) to indicate use of buffering.