Last active
December 20, 2015 08:09
-
-
Save ajduke/6098697 to your computer and use it in GitHub Desktop.
Example 1 - GSON Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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