Fastjson 实体类JSON化过滤字段操作-PropertyFilter
过滤实体类中年龄等于5的字段
List<Users> models=new ArrayList<>();
for(int i=0;i<11;i++){
Users model=new Users();
model.setAge(i);
model.setName("liu");
models.add(model);
}
PropertyFilter profilter = new PropertyFilter(){
@Override
public boolean apply(Object object, String name, Object value) {
if(name.equalsIgnoreCase("age")&&value.equals(5)){
return false;
}
return true;
}
};
OkhttpUtils.println(JSON.toJSONString(models, profilter));
打印:
[{“age”:0,”name”:”liu”},{“age”:1,”name”:”liu”},{“age”:2,”name”:”liu”},{“age”:3,”name”:”liu”},{“age”:4,”name”:”liu”},{“name”:”liu”},{“age”:6,”name”:”liu”},{“age”:7,”name”:”liu”},{“age”:8,”name”:”liu”},{“age”:9,”name”:”liu”},{“age”:10,”name”:”liu”}]
--------------------- 作者:Arisono 来源:CSDN 原文:https://blog.csdn.net/qingfeng812/article/details/73332034?utm_source=copy 版权声明:本文为博主原创文章,转载请附上博文链接!
posted on 2018-10-14 12:03 nickTimer 阅读(2385) 评论(0) 编辑 收藏 举报