Digital Marketing

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 fix Google Apps Script: Script function not found: doGet

Creating sort index in MySQL

How to fix: df shows no file systems processed on Linux