版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qingfeng812/article/details/73332034
过滤实体类中年龄等于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”}]