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

可以看到 现在成功了解决了循环引用这个问题
边栏推荐
- MySQL data manipulation language DML common commands
- MYSQL数据库底层基础专栏
- [male nanny style] teach you to open the first wechat applet
- Project scope management__ Scope management plan and scope specification
- [CSDN]C1训练题解析_第二部分_Web基础
- Learn the contents of 5g toolbox supporting NR through the NR resources provided by MATLAB
- When you need to use some functions of STM32, but 51 can't realize them, 32 naturally doesn't need to learn
- Embedded systems are inherently flawed. Compared with the Internet, there are so many holes that it is simply difficult to walk away from
- 內存數據庫究竟是如何發揮內存優勢的?
- Synchronization control between tasks
猜你喜欢

Quelle langue choisir pour programmer un micro - ordinateur à puce unique
![[csdn] C1 analyse des questions de formation Partie III Bar _ JS Foundation](/img/b2/68d53ad09688f7fc922ac65e104f15.png)
[csdn] C1 analyse des questions de formation Partie III Bar _ JS Foundation

PRACH --- originator

Embedded systems are inherently flawed. Compared with the Internet, there are so many holes that it is simply difficult to walk away from

没有多少人能够最终把自己的兴趣带到大学毕业上

端午节快乐!—— canvas写的粽子~~~~~

手机都算是单片机的一种,只不过它用的硬件不是51的芯片

SCM career development: those who can continue to do it have become great people. If they can't endure it, they will resign or change their careers

Shell logic case

STM32 serial port usart1 routine
随机推荐
Electronic product design
2020-08-23
Seven sorting of ten thousand words by hand (code + dynamic diagram demonstration)
Code word in NR
Learn the contents of 5g toolbox supporting NR through the NR resources provided by MATLAB
PRACH --- originator
Install local sources using yum
Nodemcu-esp8266 development (vscode+platformio+arduino framework): Part 4 --blinker_ DHT_ WiFi (lighting technology app control + temperature and humidity data app display)
Development of electrical fire system
GPIO port details, Hal library operation keys
要選擇那種語言為單片機編寫程序呢
Leetcode daily question (2305. fair distribution of cookies)
没有多少人能够最终把自己的兴趣带到大学毕业上
STM32 serial communication principle
A lottery like scissors, stone and cloth (C language)
UCI and data multiplexing are transmitted on Pusch (Part VI) -- LDPC coding
Hal library sets STM32 clock
Design and development of biological instruments
STM32 interrupt switch
UCI and data multiplexing are transmitted on Pusch (Part V) -- polar coding