当前位置:网站首页>03 FastJson 解决循环引用
03 FastJson 解决循环引用
2022-07-03 09:15:00 【look-word】
FastJson 解决循环引用
产生原因 要被转换的对象中 存在两个相同地址的引用
代码展示:
public static void main(String[] args) {
ArrayList<Object> list = new ArrayList<>();
Object o = new Object();
list.add(o);
list.add(o);
// 输出长度
System.out.println(list.size());
// 转换成json字符的结果
System.out.println(JSONObject.toJSONString(list));
}
观看结果可知,转换出的json字符串并不是我们想要的,问题产生的大致原因就是fastjson在做转换时,发现已经有一个引用指向了这个位置,从而后来的这个指向的了之前的那个引用,那么这个问题该如何解决呢?
// 解决循环引用
System.out.println(JSONObject.toJSONString(list,SerializerFeature.DisableCircularReferenceDetect));
可以看到 现在成功了解决了循环引用这个问题
边栏推荐
- Project scope management__ Scope management plan and scope specification
- 手机都算是单片机的一种,只不过它用的硬件不是51的芯片
- 顺利毕业[3]-博客系统 更新中。。。
- Project cost management__ Cost management technology__ Article 8 performance review
- Development of fire evacuation system
- [22 graduation season] I'm a graduate yo~
- Leetcode daily question (2305. fair distribution of cookies)
- 学历是一张通行证,门票,你有了它,可以踏入更高层次的环境里
- How does the memory database give full play to the advantages of memory?
- Characteristics of PUCCH formats
猜你喜欢
MySQL Data Definition Language DDL common commands
Fundamentals of Electronic Technology (III)_ Chapter 2 principle of amplification circuit__ Crystal triode and field effect triode
MySQL data manipulation language DML common commands
Nodemcu-esp8266 development (vscode+platformio+arduino framework): Part 5 --blinker_ MIOT_ MULTI_ Outside (lighting technology app + Xiaoai classmate control socket multiple jacks)
端午节快乐!—— canvas写的粽子~~~~~
I didn't think so much when I was in the field of single chip microcomputer. I just wanted to earn money to support myself first
【顺利毕业】[1]-游览 [学生管理信息系统]
[csdn] C1 analyse des questions de formation Partie III Bar _ JS Foundation
没有多少人能够最终把自己的兴趣带到大学毕业上
Programming ideas are more important than anything, not more than who can use several functions, but more than the understanding of the program
随机推荐
嵌入式系统没有特别明确的定义
Embedded systems are inherently flawed. Compared with the Internet, there are so many holes that it is simply difficult to walk away from
单片机学到什么程度能找到工作,这个标准不好量化
Leetcode daily question (2109. adding spaces to a string)
Schematic diagram and connection method of six pin self-locking switch
[csdn] C1 analyse des questions de formation Partie III Bar _ JS Foundation
QT qcombobox QSS style settings
要選擇那種語言為單片機編寫程序呢
Assignment to '*' form incompatible pointer type 'linkstack' {aka '*'} problem solving
在三线城市、在县城,很难毕业就拿到10K
Leetcode daily question (2305. fair distribution of cookies)
Leetcode daily question (1162. as far from land as possible)
顺利毕业[2]-学生健康管理系统 功能开发中。。。
Electronic product design, MCU development, circuit cloning
Raspberry pie installation SciPy
Implementing distributed lock with redis
Epoll read / write mode in LT and et modes
Shell logic case
In third tier cities and counties, it is difficult to get 10K after graduation
MYSQL数据库底层基础专栏