当前位置:网站首页>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));

可以看到 现在成功了解决了循环引用这个问题
边栏推荐
- 要选择那种语言为单片机编写程序呢
- Raspberry pie installation SciPy
- Process communication - semaphore
- 学习开发没有捷径,也几乎不存在带路会学的快一些的情况
- Stm32f407 key interrupt
- Definition and use of enum in C language
- 顺利毕业[3]-博客系统 更新中。。。
- [CSDN] C1 training problem analysis_ Part II_ Web Foundation
- Leetcode daily question (1162. as far from land as possible)
- STM32 interrupt priority management
猜你喜欢
![[CSDN] C1 training problem analysis_ Part IV_ Advanced web](/img/ee/2e9756cc0e2e6eda83e1b2304c0bd6.png)
[CSDN] C1 training problem analysis_ Part IV_ Advanced web

在三线城市、在县城,很难毕业就拿到10K

我想各位朋友都应该知道学习的基本规律就是:从易到难

There is no specific definition of embedded system

Development of fire evacuation system

Oracle数据库 SQL语句执行计划、语句跟踪与优化实例
![[CSDN]C1训练题解析_第二部分_Web基础](/img/91/72cdea3eb3f61315595330d2c9016d.png)
[CSDN]C1训练题解析_第二部分_Web基础

应用最广泛的8位单片机当然也是初学者们最容易上手学习的单片机

Nr--- Pusch I: sorting out the agreement process
![顺利毕业[3]-博客系统 更新中。。。](/img/91/72cdea3eb3f61315595330d2c9016d.png)
顺利毕业[3]-博客系统 更新中。。。
随机推荐
Intelligent home design and development
[CSDN] C1 training problem analysis_ Part II_ Web Foundation
Electronic product design, MCU development, circuit cloning
Leetcode daily question (2305. fair distribution of cookies)
Flink learning notes (VIII) multi stream conversion
MySQL Data Definition Language DDL common commands
Install local sources using yum
Education is a pass and ticket. With it, you can step into a higher-level environment
The number of weak characters in the game (1996)
Epoll read / write mode in LT and et modes
Nr-prach: access scenario and access process
Fundamentals of Electronic Technology (III)__ Chapter 1 resistance of parallel circuit
UCI and data multiplexing are transmitted on Pusch (Part V) -- polar coding
内存数据库究竟是如何发挥内存优势的?
编程思想比任何都重要,不是比谁多会用几个函数而是比程序的理解
2021-09-26
Difference of EOF
There is no specific definition of embedded system
Process communication - semaphore
学习开发没有捷径,也几乎不存在带路会学的快一些的情况