FastJson过滤字段

来源:互联网 发布:香酸枣淘宝 编辑:程序博客网 时间:2024/04/29 22:17

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;// 不过滤}};

原创粉丝点击