1、在对象对应字段前面加transient,表示该字段不用序列化,即在生成json的时候就不会包含该字段了。
比如
private transient String name;
2、在对象响应字段前加注解,这样生成的json也不包含该字段。
@JSONField(serialize=false) private String name;
3.指定的字段才能显示出来
SimplePropertyPreFilter filter = new SimplePropertyPreFilter( MpBannerEntity.class,"title","thumbUrl","url"); JSONObject.toJSONString(要过滤的对象,filter)
4:过滤指定字段
final String[] arr = new String[] { "ticketNo","status","updateTime","createTime" }; PropertyFilter propertyFilter = new PropertyFilter() { public boolean apply(Object object,String name,Object value) { for (String string : arr) { if (name.equalsIgnoreCase(string)) { return false;// 过滤掉 } } return true;// 不过滤 } };
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。