//将对象转换成json格式的时候,常常需要排除一些字段(例如延迟加载的字段)。在fastjson库中,我们可以使用SimplePropertyPreFilter忽略掉这些属性。
PropertyPreFilters.MySimplePropertyPreFilter excludefilter = new PropertyPreFilters().addFilter();
//排除敏感属性字段
String[] EXCLUDE_PROPERTIES = {"password", "oldPassword", "newPassword", "confirmPassword"};
excludefilter.addExcludes(EXCLUDE_PROPERTIES);
String params = JSONObject.toJSONString(map, excludefilter);
对象转换成json格式使用过滤器排除一些字段
最新推荐文章于 2023-04-28 23:29:12 发布