JSON过滤器之SimplePropertyPreFilter-排查指定属性

JSONObject json=new JSONObject ();
json.put("account","zhangshengnan");
json.put("name","张胜男");
json.put("age","16");
json.put("sex","男");
json.put("level","1");

//1、添加指定的字段
SimplePropertyPreFilter filter = new SimplePropertyPreFilter();
filter.getIncludes().add("account");
filter.getIncludes().add("name");
JSONObject jsonObject=JSONObject.parseObject(JSON.toJSONString(contractSealVO, filter));
输出:{
  "account":"zhangshengnan",
  "name":"张胜男"
  }

//2、排除指定的字段
SimplePropertyPreFilter filter = new SimplePropertyPreFilter();
filter.getExcludes().add("age");
JSONObject jsonObject=JSONObject.parseObject(JSON.toJSONString(contractSealVO, filter));
输出:{
  "account":"zhangshengnan",
  "name":"张胜男",
  "sex":"男",
  "level":"1"
  }
 

posted on 2023-09-28 14:13  河边的男孩  阅读(415)  评论(0编辑  收藏  举报

导航