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

可以看到 现在成功了解决了循环引用这个问题
边栏推荐
- Flink learning notes (10) Flink fault tolerance mechanism
- Definition and use of enum in C language
- [csdn] C1 analyse des questions de formation Partie III Bar _ JS Foundation
- 嵌入式本来就很坑,相对于互联网来说那个坑多得简直是难走
- UCI and data multiplexing are transmitted on Pusch - placement of data and UCI positions (Part III)
- Epollet lessons
- Convert IP address to int
- CEF download, compile project
- 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
- 学历是一张通行证,门票,你有了它,可以踏入更高层次的环境里
猜你喜欢

Error output redirection

Characteristics of PUCCH formats

Fundamentals of Electronic Technology (III)__ Chapter 1 resistance of parallel circuit

Nodemcu-esp8266 development (vscode+platformio+arduino framework): Part 5 --blinker_ MIOT_ MULTI_ Outside (lighting technology app + Xiaoai classmate control socket multiple jacks)
![Successful graduation [3]- blog system update...](/img/91/72cdea3eb3f61315595330d2c9016d.png)
Successful graduation [3]- blog system update...

UCI and data multiplexing are transmitted on Pusch - placement of data and UCI positions (Part III)

How MySQL modifies null to not null

The cyclic shift of PUCCH in NR channel is generated by MATLAB

Mysql database underlying foundation column

Stm32f407 key interrupt
随机推荐
[successful graduation] [1] - visit [student management information system]
Leetcode daily question (985. sum of even numbers after queries)
Leetcode daily question (931. minimum falling path sum)
PIP references domestic sources
2020-08-23
嵌入式系统没有特别明确的定义
A lottery like scissors, stone and cloth (C language)
Definition and use of enum in C language
When you need to use some functions of STM32, but 51 can't realize them, 32 naturally doesn't need to learn
新系列单片机还延续了STM32产品家族的低电压和节能两大优势
UCI and data multiplexing are transmitted on Pusch (Part VI) -- LDPC coding
numpy. Reshape() and resize() functions
The number of weak characters in the game (1996)
[CSDN]C1訓練題解析_第三部分_JS基礎
UCI and data multiplexing are transmitted on Pusch - determine the bit number of harqack, csi1 and csi2 (Part II)
Project cost management__ Cost management technology__ Article 8 performance review
Electronic product design
Assignment to '*' form incompatible pointer type 'linkstack' {aka '*'} problem solving
单片机现在可谓是铺天盖地,种类繁多,让开发者们应接不暇
Nr--- Pusch I: sorting out the agreement process