• 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 版权声明:本文为博主原创文章,转载请附上博文链接!

  • 相关阅读:
    完成卸载vs2010后再安装
    图片集合,可用作商品列表
    无可奈何花落去
    Uncaught TypeError: Cannot read property 'msie' of undefined
    CodeGenerator.cs
    年月日控件
    SQL GETDATE()日期格式化函数
    股票操作要点
    Rust 错误处理, 包裹错误
    使用 Rust 实现并查集
  • 原文地址:https://www.cnblogs.com/toSeeMyDream/p/9785846.html
Copyright © 2020-2023  润新知