Java
org.json
// build.gradle
compile 'org.json:json:20151123'
// object to json
JSONObject jsonObject = new JSONObject(model);
String json = jsonObject.toString(4);
// json to object
Jackson JSON Processor
gradlew dependencies
// build.gradle
compile 'com.fasterxml.jackson.core:jackson-databind:2.5.3'
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(SerializationFeature.INDENT_OUTPUT, true);
// object to json
String json = objectMapper.writeValueAsString(model);
// json to object
Model model = objectMapper.readValue(json, Model.class);
Google-gson
// build.gradle
compile 'com.google.code.gson:gson:2.5'
Gson gson = new GsonBuilder().setPrettyPrinting().create();
// object to json
String json = gson.toJson(model);
// json to object
Model model = gson.fromJson(json, Model.class);
fastjson
// build.gradle
compile 'com.alibaba:fastjson:1.2.7'
// object to json
String json = JSON.toJSONString(model);
// json to object
Model model = JSON.parseObject(json, Model.class);
JavaScript