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:

Popular posts from this blog

How to delete / clear queue of PowerMTA