首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Gson:如何从没有注释的序列化中排除特定的字段?

Gson:如何从没有注释的序列化中排除特定的字段?

提问于 2017-12-26 16:36:32
回答 2关注 0查看 566

我正在努力学习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;

}

我可以使用GsonBuilder,并添加一个ExclusionStrategy的字段名称像firstName或,country但我似乎无法设法排除像某些领域的属性country.name。

使用该方法public boolean shouldSkipField(FieldAttributes fa),FieldAttributes不包含足够的信息来匹配字段与过滤器country.name。

使用Gson

<interceptor-ref name=""json"">

<param name=""enableSMD"">true</param>

<param name=""excludeProperties"">

login.password,

studentList.*\.sin

</param>

</interceptor-ref>

回答

和开发者交流更多问题细节吧,去 写回答
相关文章

相似问题

相关问答用户
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档