Skip to content

Instantly share code, notes, and snippets.

@ajduke

ajduke/Example1.java

Last active Dec 20, 2015
Embed
What would you like to do?
Example 1 - GSON Example
final Gson gson = new Gson();
// original object instantiation
ModelObject modelObject = new ModelObject("myname", 12, true, 2.3);
System.out.println("toJson ---");
System.out.println("Original Java object : " + modelObject);
// converting an object to json object
String json = gson.toJson(modelObject);
System.out.println("Converted JSON string is : " + json);
System.out.println("fromJson----");
// getting object from json representation
System.out.println("Original JSON string is : " + json);
// converting json to object
ModelObject modelObject1 = gson.fromJson(json, ModelObject.class);
System.out.println("Converted Java object : " + modelObject1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment