过滤实体类中年龄等于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,{“age”:2,{“age”:3,{“age”:4,{“name”:”liu”},{“age”:6,{“age”:7,{“age”:8,{“age”:9,{“age”:10,”name”:”liu”}]