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"
}