implementation here } // Excludes any field (or class) that is tagged with an "@FooAnnotation" private static class FooAnnotationExclusionStrategy implements ExclusionStrategy { public boolean shouldSkipClass(Class<?> clazz) { return clazz.getAnnotation(FooAnnotation.class) != null; } public boolean shouldSkipField(FieldAttributes f) { return f.getAnnotation(FooAnnotation.class) != null; } }
Now if you want to configure {@code Gson} to use a user defined exclusion strategy, thenthe {@code GsonBuilder} is required. The following is an example of how you can use the{@code GsonBuilder} to configure Gson to use one of the above sample:
ExclusionStrategy excludeStrings = new UserDefinedExclusionStrategy(String.class); Gson gson = new GsonBuilder() .setExclusionStrategies(excludeStrings) .create();
@author Inderjeet Singh
@author Joel Leitch
@see GsonBuilder#setExclusionStrategies(ExclusionStrategy)
@since 1.4