解决FastJson循环引用的问题
temp 本来被循环引用,运行方法报错。
解决方法:对temp进行处理
SerializerFeature feature = SerializerFeature.DisableCircularReferenceDetect; temp = JSONObject.parseObject(JSON.toJSONString(temp,feature));
以下为情景复现
public JSONObject convertQueryGroupInterface(JSONObject querygroup) {
JSONArray group = (JSONArray) querygroup.get("treeNodes");
JSONArray convert = new JSONArray();
JSONObject temp = new JSONObject();
JSONObject temp1 = new JSONObject();
SerializerFeature feature = SerializerFeature.DisableCircularReferenceDetect;
JSONObject result = null;
for (int i = 0; i <group.size(); i++){
temp1 = (JSONObject) group.get(i);
if (group != null){
temp = JSONObject.parseObject(JSON.toJSONString(temp,feature));//解决FastJson循环引用的问题
temp.put("nodeId", temp1.get("groupid"));
temp.put("nodeType", temp1.get("nodeType"));
temp.put("nodeName", temp1.get("nodeName"));
temp.put("isLeaf", false);
temp.put("expanded", false);
temp.put("checkStatus",temp1.get("groupstatus"));
}
convert.add(i,temp);
System.out.println("convert内容:"+convert);
}
for (int i = 0 ; i < convert.size() ; i ++){
result = convert.getJSONObject(i);
}
return result;
}
博客:https://dianedii.top/