Nov 5, 2017

How To Convert Java Object To / From JSON

Use Gson from Google is very convenient.

//To JSON:
DataObject obj = new DataObject();
Gson gson = new Gson();
// convert java object to JSON format,
// and returned as JSON formatted string 
String json = gson.toJson(obj);        
//From JSON:
//convert the json string back to object
DataObject obj = gson.fromJson(br, DataObject.class);
Gson Maven Dependency:

Featured Post

Setup Chinese Input Method in Ubuntu 17.10 Artful

sudo apt install ibus-sunpinyin After either of those commands do not forget to restart the IBus daemon ibus restart You might need t...