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

可以看到 现在成功了解决了循环引用这个问题
边栏推荐
- Development of electrical fire system
- Seven sorting of ten thousand words by hand (code + dynamic diagram demonstration)
- [Li Kou brush question notes (II)] special skills, module breakthroughs, classification and summary of 45 classic questions, and refinement in continuous consolidation
- 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
- Leetcode daily question (2212. maximum points in an archery competition)
- Convert IP address to int
- STM32 external interrupt experiment
- Getting started with JMX, MBean, mxbean, mbeanserver
- Basic knowledge of MySQL database (an introduction to systematization)
- 內存數據庫究竟是如何發揮內存優勢的?
猜你喜欢

Fundamentals of Electronic Technology (III)_ Chapter 2 principle of amplification circuit__ Crystal triode and field effect triode

IDEA远程断点调试jar包项目

要選擇那種語言為單片機編寫程序呢

编程思想比任何都重要,不是比谁多会用几个函数而是比程序的理解

Exception handling of arm
![Successful graduation [3]- blog system update...](/img/91/72cdea3eb3f61315595330d2c9016d.png)
Successful graduation [3]- blog system update...

STM32 serial port usart1 routine

Runtime. getRuntime(). GC () and runtime getRuntime(). The difference between runfinalization()

How does the memory database give full play to the advantages of memory?

Stm32f407 key interrupt
随机推荐
Nr-prach:prach format and time-frequency domain
STM32 serial port usart1 routine
Leetcode daily question (2109. adding spaces to a string)
[CSDN] C1 training problem analysis_ Part II_ Web Foundation
Flink CDC practice (including practical steps and screenshots)
单片机职业发展:能做下去的都成牛人了,熬不动就辞职或者改行了
【男保姆式】教你打开第一个微信小程序
Electronic product design
Fundamentals of Electronic Technology (III)__ Logic gate symbols in Chapter 5
A lottery like scissors, stone and cloth (C language)
Oracle数据库 SQL语句执行计划、语句跟踪与优化实例
Project cost management__ Topic of comprehensive calculation
开学实验里要用到mysql,忘记基本的select语句怎么玩啦?补救来啦~
Leetcode daily question (1024. video sticking)
C language enumeration type
PIP references domestic sources
新系列单片机还延续了STM32产品家族的低电压和节能两大优势
Process communication - semaphore
Getting started with shell programming
Seven sorting of ten thousand words by hand (code + dynamic diagram demonstration)