Skip to content

Instantly share code, notes, and snippets.

@ajduke

ajduke/Ex35.java

Created Jan 5, 2014
Embed
What would you like to do?
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
You can’t perform that action at this time.