Skip to content

Instantly share code, notes, and snippets.

@ajduke

ajduke/Example3.java

Last active Dec 20, 2015
Embed
What would you like to do?
Gson gson = new Gson();
// original object
ModelObject modelObject = new ModelObject("namesake", 50, true, 4.3);
System.out.print("Original Java object : ");
System.out.println(modelObject);
// converting to an json representation
String json = gson.toJson(modelObject);
System.out.print("Converted JSON string is : ");
System.out.println(json);
// getting back the object from json representation
ModelObject modelObject3 = gson.fromJson(json, ModelObject.class);
System.out.print("Converted Java object : ");
System.out.println(modelObject3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment