Fastjson reports "$ref" circular reference error

2020/11/30 Fastjson

Fastjson reports “$ref” circular reference error 发散

故事要从bug开始

JSONArray array = new JSONArray();
JSONObject item = new JSONObject();
for (int i = 0; i < 5; i++) {
    item.put("id", i);
    array.set(i, item);
}
System.out.println(JSON.toJSONString(array));

解决方法

在循环开始处new JSONObjec或者item.clone, 我从网上也找到了

JSON.toJSONString(list, SerializerFeature.DisableCircularReferenceDetact); 
//Means to disable ref duplicate reference

但我本意并不上要重复使用一个对象。哈哈

Readlist

Search

    Categories Cloud

    Life Linux C/CPP Database Web Benchmarks Software Data Python TCP/IP Financial Stock Bug Golang Rust General Infrastructure TODO Movie Multitenancy Java Ant Algorithm Fastjson Death Build Deploy Education India Aamir Khan Society Female Learning Method OJ Interviewee Interviewer AVL Tree MyBatis Code Reading Design Diary Dating Heap Data Structure Summary Reading Love Claire Mcfall Ferryman Zodiac Astrology Chinese Calculator flink Dubbo docker redis

    Table of Contents