Jackson Streaming API: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 14: Line 14:
The central elements of the Streaming API are the ''parsers'' (<tt>org.codehaus.jackson.JsonParser</tt>) that are used for reading JSON content, and the ''generators'' (<tt>org.codehaus.jackson.JsonGenerator</tt>) that are used for writing Java state out as JSON.
The central elements of the Streaming API are the ''parsers'' (<tt>org.codehaus.jackson.JsonParser</tt>) that are used for reading JSON content, and the ''generators'' (<tt>org.codehaus.jackson.JsonGenerator</tt>) that are used for writing Java state out as JSON.


This is an example of how to create a parser that reads JSON from a file and parses it:
=JSON Parsing with Streaming API=


This is an example of how to create a generator that writes JSON from Java state:
 
Playground:
 
 
=Writing Java State as JSON with Streaming API=
 
Playground:

Revision as of 19:57, 25 February 2017

External

Internal

Overview

The Streaming API reads and writes JSON as a series of discrete events, in a mode called "incremental parsing/generation". The concepts behind the Streaming API are similar to those of StAX. The Streaming API has the lowest overhead and its the fastest of all methods. The other two methods (Tree Model and Data Binding) are built in top of it. However, this is not the most convenient method, because is relatively low level. All content to read or write has to be processed in the order the input comes or the output has to go out. Random access is not possible. Also, no Java objects are created, unless specifically requested, and even then only very basic types are supported: String and byte[].

The central elements of the Streaming API are the parsers (org.codehaus.jackson.JsonParser) that are used for reading JSON content, and the generators (org.codehaus.jackson.JsonGenerator) that are used for writing Java state out as JSON.

JSON Parsing with Streaming API

Playground:


Writing Java State as JSON with Streaming API

Playground: