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

可以看到 现在成功了解决了循环引用这个问题
边栏推荐
- Nr-prach: access scenario and access process
- Leetcode daily question (985. sum of even numbers after queries)
- Fundamentals of Electronic Technology (III)__ Logic gate symbols in Chapter 5
- Development of fire power monitoring system
- numpy. Reshape() and resize() functions
- 编程思想比任何都重要,不是比谁多会用几个函数而是比程序的理解
- [combinatorics] Introduction to Combinatorics (combinatorial thought 2: mathematical induction | mathematical induction promotion | multiple induction thought)
- 要选择那种语言为单片机编写程序呢
- 对于新入行的同学,如果你完全没有接触单片机,建议51单片机入门
- Successful graduation [2] - student health management system function development...
猜你喜欢

Nr--- Pusch I: sorting out the agreement process

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

Flink learning notes (XI) table API and SQL
![[CSDN]C1训练题解析_第四部分_Web进阶](/img/ee/2e9756cc0e2e6eda83e1b2304c0bd6.png)
[CSDN]C1训练题解析_第四部分_Web进阶

MySQL environment variable configuration

uniapp 实现微信小程序全局分享及自定义分享按钮样式
![[CSDN]C1訓練題解析_第三部分_JS基礎](/img/b2/68d53ad09688f7fc922ac65e104f15.png)
[CSDN]C1訓練題解析_第三部分_JS基礎

Stm32f407 key interrupt

Leetcode daily question (2090. K radius subarray averages)

一个可执行的二进制文件包含的不仅仅是机器指令
随机推荐
Nr--- Pusch I: sorting out the agreement process
MYSQL数据库底层基础专栏
Fundamentals of Electronic Technology (III)_ Integrated operational amplifier and its application__ Basic arithmetic circuit
Project cost management__ Cost management technology__ Article 8 performance review
【力扣刷题笔记(二)】特别技巧,模块突破,45道经典题目分类总结,在不断巩固中精进
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
[CSDN]C1訓練題解析_第三部分_JS基礎
单片机现在可谓是铺天盖地,种类繁多,让开发者们应接不暇
When you need to use some functions of STM32, but 51 can't realize them, 32 naturally doesn't need to learn
JS基础-原型原型链和宏任务/微任务/事件机制
Assignment to '*' form incompatible pointer type 'linkstack' {aka '*'} problem solving
Fundamentals of Electronic Technology (III)__ Logic gate symbols in Chapter 5
[csdn] C1 analyse des questions de formation Partie III Bar _ JS Foundation
编程思想比任何都重要,不是比谁多会用几个函数而是比程序的理解
Project cost management__ Cost management technology__ Article 7 completion performance index (tcpi)
新系列单片机还延续了STM32产品家族的低电压和节能两大优势
Electronic product design, MCU development, circuit cloning
万字手撕七大排序(代码+动图演示)
Electronic product design
Nodemcu-esp8266 development (vscode+platformio+arduino framework): Part 5 --blinker_ MIOT_ MULTI_ Outside (lighting technology app + Xiaoai classmate control socket multiple jacks)