I\'m trying to learn Gson and I\'m struggling with field exclusion. Here are my classes
public class Student {
private Long id;
privat
I solved this problem with custom annotations. This is my "SkipSerialisation" Annotation class:
@Target (ElementType.FIELD)
public @interface SkipSerialisation {
}
and this is my GsonBuilder:
gsonBuilder.addSerializationExclusionStrategy(new ExclusionStrategy() {
@Override public boolean shouldSkipField (FieldAttributes f) {
return f.getAnnotation(SkipSerialisation.class) != null;
}
@Override public boolean shouldSkipClass (Class> clazz) {
return false;
}
});
Example :
public class User implements Serializable {
public String firstName;
public String lastName;
@SkipSerialisation
public String email;
}