Created
January 5, 2014 14:56
-
-
Save ajduke/8269156 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
public class Ex35 { | |
public static void main(String[] args) { | |
Gson gson = null; | |
Developer developer = new Developer(); | |
String json = null; | |
gson = new Gson(); | |
json = gson.toJson(developer); | |
System.out.println("Default behaviuor...."); | |
System.out.println(json); | |
// exclude field having String | |
gson = new GsonBuilder().setExclusionStrategies( | |
new ExclusionStrategyImpl(List.class)).create(); | |
json = gson.toJson(developer); | |
System.out.println("\nExclude fields with type - List"); | |
System.out.println(json); | |
// exclude field having List | |
gson = new GsonBuilder().setExclusionStrategies( | |
new ExclusionStrategyImpl(String.class)).create(); | |
json = gson.toJson(developer); | |
System.out.println("\nExclude fields with type - String"); | |
System.out.println(json); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment