/** * * @Title: getJSONFilter * @Description: 过滤json中的属性 * @author HUAZAI * @param includes 需要的属性 * @param excludes 需要去除的属性 * @return 返回类型 : SimplePropertyPreFilter * <ul> * <li></li> * <li></li> * <ul> * @throws @date 2017年11月21日 下午3:16:46 */ public static SimplePropertyPreFilter getJSONFilter(String[] includes, String[] excludes) { SimplePropertyPreFilter filter = new SimplePropertyPreFilter(); Set<String> excludesTemp = filter.getExcludes(); Set<String> includesTemp = filter.getIncludes(); if (includes != null && includes.length != 0) { for (String str : includes) { includesTemp.add(str); } } if (excludes != null && excludes.length != 0) { for (String str : excludes) { excludesTemp.add(str); } } return filter; }
使用方式
SimplePropertyPreFilter jsonFilter = CommonUtils.getJSONFilter(null, excludes); String str = JSON.toJSONString(payloadUtils, jsonFilter);