Created
August 12, 2013 16:19
-
-
Save ajduke/6212438 to your computer and use it in GitHub Desktop.
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
Gson gson = new Gson(); | |
System.out.println("Default behaviour "); | |
GsonBuilder gsonBuilder = new GsonBuilder(); | |
Gson prettyGson = gsonBuilder.setPrettyPrinting().create(); | |
String json = prettyGson.toJson(new Developer()); | |
System.out.println(json); | |
System.out.println("Ignoring/excluding fields "); | |
GsonBuilder excludeFieldsWithModifiers = gsonBuilder | |
.excludeFieldsWithModifiers(Modifier.PRIVATE); | |
Gson create = excludeFieldsWithModifiers.create(); | |
String json2 = create.toJson(new Developer()); | |
System.out.println(json2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment