序列化泛型
String result = "{}";
BaseResult<String> accountResult = JSON.parseObject(result,new TypeReference<BaseResult<String>>() {});
Response处理返回值
default ResponseEntity<String> handleAjaxJsonResponse(Object content) {
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.set("Content-Type", "application/json; charset=UTF-8");
// DisableCircularReferenceDetect来禁止循环引用检测
return new ResponseEntity<>(JSONObject.toJSONString(content, SerializerFeature.DisableCircularReferenceDetect),
responseHeaders, HttpStatus.OK);
}
过滤字段
SimplePropertyPreFilter filter = new SimplePropertyPreFilter();
filter.getExcludes().add("name");
System.out.println(JSON.toJSONString(obj, filter));
过滤多个字段
SimplePropertyPreFilter filter1 = new SimplePropertyPreFilter(User.class);
filter1 .getExcludes().add("name");
SimplePropertyPreFilter filter2 = new SimplePropertyPreFilter(Dept.class);
filter2 .getExcludes().add("deptId");
System.out.println(JSON.toJSONString(obj, new SimplePropertyPreFilter[] {filter1, filter2})));