Jackson: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 19: Line 19:
==Streaming API==
==Streaming API==


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 [[JAXP_StAX#jackson|StAX]]. The Streaming API has the lowest overhead and its the fastest of all methods. The other two methods ([[#Tree_Model|Tree Model]] and [[#Data_Binding|Data Binding]]) are built in top of it.
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 [[JAXP_StAX#jackson|StAX]]. The Streaming API has the lowest overhead and its the fastest of all methods. The other two methods ([[#Tree_Model|Tree Model]] and [[#Data_Binding|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 <tt>org.codehaus.jackson.JsonParser</tt> for reading and <tt>org.codehaus.jackson.JsonGenerator</tt> for writing.
The central elements of the Streaming API are <tt>org.codehaus.jackson.JsonParser</tt> for reading and <tt>org.codehaus.jackson.JsonGenerator</tt> for writing.

Revision as of 17:26, 25 February 2017

External

Internal

Overview

Jackson is a Java library for processing JSON data format. It has support for marshaling and unmarshalling Java to and from JSON. It has a JAX-RS content handler that can automatically convert between Java objects and JSON, and vice-versa. It can generate JSON schemas from a Java object model.

JSON Processing Methods

Jackson offers three alternative methods for processing JSON:

Streaming API

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 org.codehaus.jackson.JsonParser for reading and org.codehaus.jackson.JsonGenerator for writing.

Tree Model

Tree model is arguably the most flexible of all three methods.

Data Binding

Data Binding is arguably the most convenient of all three methods.

JSON to Java

JSON to Java

Java to JSON

Java to JSON


TODO and delete: https://home.feodorov.com:9443/wiki/Wiki.jsp?page=Jackson