Skip to content

Instantly share code, notes, and snippets.

@ajduke
Last active December 20, 2015 08:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajduke/6098733 to your computer and use it in GitHub Desktop.
Save ajduke/6098733 to your computer and use it in GitHub Desktop.
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