当前位置:网站首页>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));
可以看到 现在成功了解决了循环引用这个问题
边栏推荐
- Assignment to '*' form incompatible pointer type 'linkstack' {aka '*'} problem solving
- Electronic product design
- Quelle langue choisir pour programmer un micro - ordinateur à puce unique
- Electronic product design, MCU development, circuit cloning
- Implementing distributed lock with redis
- Shell logic case
- 开学实验里要用到mysql,忘记基本的select语句怎么玩啦?补救来啦~
- Fundamentals of Electronic Technology (III)__ Chapter 6 combinational logic circuit
- 没有多少人能够最终把自己的兴趣带到大学毕业上
- Uniapp realizes global sharing of wechat applet and custom sharing button style
猜你喜欢
UCI and data multiplexing are transmitted on Pusch - determine the bit number of harqack, csi1 and csi2 (Part II)
MySQL data manipulation language DML common commands
Fundamentals of Electronic Technology (III)_ Chapter 2 principle of amplification circuit__ Crystal triode and field effect triode
Runtime.getRuntime().gc() 和 Runtime.getRuntime().runFinalization() 的区别
Nr-prach: access scenario and access process
MYSQL数据库底层基础专栏
Leetcode daily question (2090. K radius subarray averages)
手机都算是单片机的一种,只不过它用的硬件不是51的芯片
STM32 external interrupt experiment
新系列单片机还延续了STM32产品家族的低电压和节能两大优势
随机推荐
Oracle数据库 SQL语句执行计划、语句跟踪与优化实例
Implementing distributed lock with redis
我想各位朋友都应该知道学习的基本规律就是:从易到难
2021-01-03
Nr-prach:prach format and time-frequency domain
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
2020-08-23
Oracle database SQL statement execution plan, statement tracking and optimization instance
[CSDN] C1 training problem analysis_ Part II_ Web Foundation
Electronic product design
[combinatorics] Introduction to Combinatorics (context of combinatorics | skills of combinatorics | thought of combinatorics 1: one-to-one correspondence)
Nr--- Pusch I: sorting out the agreement process
How does the nr-prach receiver detect the relationship between prembleid and Ta
NR technology -- MIMO
[graduation successful] [1] - tour [Student Management Information System]
How MySQL modifies null to not null
The number of weak characters in the game (1996)
Development of electrical fire system
Learn the contents of 5g toolbox supporting NR through the NR resources provided by MATLAB
Eight working modes of stm32gpio and chip naming rules