Skip to content

Instantly share code, notes, and snippets.

@ajduke
Created January 5, 2014 14:56
Show Gist options
  • Save ajduke/8269156 to your computer and use it in GitHub Desktop.
Save ajduke/8269156 to your computer and use it in GitHub Desktop.
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