Monday, 13 May 2013

Java JSON Data Binding Example ( jackson processor)

Java JSON data Binding

JSON (JavaScript Object Notation), is a simple and easy to read and write data exchange format. In this tutorial
we focus three opensource java library which process the json data, which are Jackson, Google Gson and JSON.simple.

Jackson


It is a high performance JSON processor. There are some examples given here.

Jackson data binding example-Object & JSON :

In this example we are showing how to convert java object to/from JSON.
before starting with jackson, you have to download the library and include in your java classpath from Here
Create a POJO:
Person object, initialized with some values

Java Object to JSON:
Convert an Person object into JSON formatted string, and save it into a file person.json.

Output will be
{"name":"Wakil","age":29,"messages":["Message 1","Message 2","Message 3"]}

JSON to Java Object:
Read JSON string from file person.json, and convert it back to Java object.

Output will be Person [age=29, name=Wakil, messages=[Message 1, Message 2, Message 3]]

No comments:

Post a Comment