本文共 1019 字,大约阅读时间需要 3 分钟。
过滤实体类中年龄等于5的字段
Listmodels=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”}]