fastjson 过滤掉多余的字段


public static void main(String[] args) {
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("name", "张三");
    jsonObject.put("age", "13");
    System.out.println(JSONObject.toJSONString(jsonObject,filter("age")));
}
public static SerializeFilter filter(String... keys) {
    List arr = (keys != null && keys.length > 0) ? Arrays.asList(keys) : null;
    PropertyFilter propertyFilter = new PropertyFilter() {
        @Override
        public boolean apply(Object o, String s, Object o1) {
            if (arr != null && arr.contains(s)) {
                return false;
            }
            return true;
        }
    };
    return propertyFilter;
}

你可能感兴趣的:(JSON,java,json)