Jackson Tree Model: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 9: Line 9:
=JSON to Java with Tree Model=
=JSON to Java with Tree Model=


<tt>org.codehaus.jackson.map.ObjectMapper</tt> is the main API that builds trees from JSON content. The trees consists of <tt>JsonNode</tt>s.
<tt>org.codehaus.jackson.map.ObjectMapper</tt> is the main API that builds trees from JSON content.  


<pre>
<pre>
Line 18: Line 18:
JsonNode root = om.readTree(is);
JsonNode root = om.readTree(is);
</pre>
</pre>
The trees consists of <tt>JsonNode</tt>s. Each node has one of the following types, coded as the <tt>JsonNodeType</tt> enum:
* NULL
* BOOLEAN
* NUMBER
* STRING
* OBJECT
* ARRAY
* BINARY
* POJO
* MISSING


==JSON to Java with Tree Model Code Example==
==JSON to Java with Tree Model Code Example==

Revision as of 23:02, 25 February 2017

Internal

Overview

This method converts a JSON document into a mutable in-memory tree representation of the JSON document. Tree model is arguably the most flexible of all three methods. The tree model is similar to the XML DOM.

JSON to Java with Tree Model

org.codehaus.jackson.map.ObjectMapper is the main API that builds trees from JSON content.

InputStream is = ...

ObjectMapper om = new ObjectMapper();

JsonNode root = om.readTree(is);

The trees consists of JsonNodes. Each node has one of the following types, coded as the JsonNodeType enum:

  • NULL
  • BOOLEAN
  • NUMBER
  • STRING
  • OBJECT
  • ARRAY
  • BINARY
  • POJO
  • MISSING

JSON to Java with Tree Model Code Example


Java to JSON with Tree Model