Jackson Simple Data Binding: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 6: Line 6:


Simple data binding extracts data from JSON and initializes a in-memory Java object hierarchy. Unlike the [[Jackson#Tree_Model|tree model]], which uses <tt>JsonNode</tt>s, simple data binding uses Maps, Lists, Strings, Numbers, Booleans and nulls to represent the JSON structure.
Simple data binding extracts data from JSON and initializes a in-memory Java object hierarchy. Unlike the [[Jackson#Tree_Model|tree model]], which uses <tt>JsonNode</tt>s, simple data binding uses Maps, Lists, Strings, Numbers, Booleans and nulls to represent the JSON structure.
<tt>ObjectMapper.readValue()</tt> must be called with a Map type and it will build a Map/List/String/Number/Boolean hierarchy:
<pre>
import com.fasterxml.jackson.databind.ObjectMapper;
ObjectMapper om = new ObjectMapper();
Token token = on.readValue(inputStream, Token.class);
</pre>


=JSON to Java=
=JSON to Java=

Revision as of 19:14, 26 February 2017

Internal

Overview

Simple data binding extracts data from JSON and initializes a in-memory Java object hierarchy. Unlike the tree model, which uses JsonNodes, simple data binding uses Maps, Lists, Strings, Numbers, Booleans and nulls to represent the JSON structure.

ObjectMapper.readValue() must be called with a Map type and it will build a Map/List/String/Number/Boolean hierarchy:

import com.fasterxml.jackson.databind.ObjectMapper;

ObjectMapper om = new ObjectMapper();
Token token = on.readValue(inputStream, Token.class);

JSON to Java

JSON to Java Code Example

https://github.com/NovaOrdis/playground/blob/master/json/jackson/simple-data-binding-json-to-java/src/main/java/io/novaordis/playground/json/jackson/simpledatabinding/json2java/Main.java

Java to JSON

Java to JSON Code Example