我正在努力学习Gson,而我正在努力进行场上排斥.这是我的课程
public class Student {
private Long id;
private String firstName = "Philip";
private String middleName = "J.";
private String initials = "P.F";
private String lastName = "Fry";
private Country country;
private Country countryOfBirth;
}
public class Country {
private Long id;
private String name;
private Object other;
}
Run Code Online (Sandbox Code Playgroud)
我可以使用GsonBuilder并添加ExclusionStrategy像一个字段名称firstName或country,但我似乎无法管理排除像某些领域的性能country.name.
使用该方法public boolean shouldSkipField(FieldAttributes fa),FieldAttributes不包含足够的信息来匹配具有过滤器的字段country.name.
对于这个问题的解决方案,我将不胜感激.
PS:我想避免注释,因为我想对此进行改进并使用RegEx来过滤字段.
谢谢
编辑:我试图看看是否可以模拟Struts2 JSON插件的行为
使用Gson
<interceptor-ref name="json">
<param name="enableSMD">true</param>
<param name="excludeProperties">
login.password, …Run Code Online (Sandbox Code Playgroud)