当前位置:网站首页>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));
可以看到 现在成功了解决了循环引用这个问题
边栏推荐
- Fundamentals of Electronic Technology (III)_ Chapter 2 principle of amplification circuit__ Crystal triode and field effect triode
- Successful graduation [2] - student health management system function development...
- Definition and use of enum in C language
- 单片机学到什么程度能找到工作,这个标准不好量化
- Project cost management__ Cost management technology__ Article 7 completion performance index (tcpi)
- 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
- When you need to use some functions of STM32, but 51 can't realize them, 32 naturally doesn't need to learn
- 【順利畢業】[1]-遊覽 [學生管理信息系統]
- 要選擇那種語言為單片機編寫程序呢
- 没有多少人能够最终把自己的兴趣带到大学毕业上
猜你喜欢
SSB Introduction (PbCH and DMRs need to be supplemented)
[Li Kou brush question notes (II)] special skills, module breakthroughs, classification and summary of 45 classic questions, and refinement in continuous consolidation
Education is a pass and ticket. With it, you can step into a higher-level environment
我想各位朋友都应该知道学习的基本规律就是:从易到难
You need to use MySQL in the opening experiment. How can you forget the basic select statement? Remedy is coming~
MySQL data manipulation language DML common commands
[CSDN] C1 training problem analysis_ Part II_ Web Foundation
NR PUCCH format0 sequence generation and detection mechanism
Uniapp realizes global sharing of wechat applet and custom sharing button style
Design and development of biological instruments
随机推荐
Flink learning notes (XI) table API and SQL
2020-08-23
Stm32-hal library learning, using cubemx to generate program framework
当你需要使用STM32某些功能,而51实现不了时, 那32自然不需要学
307. Range Sum Query - Mutable
Synchronization control between tasks
Leetcode daily question (2305. fair distribution of cookies)
Runtime. getRuntime(). GC () and runtime getRuntime(). The difference between runfinalization()
Uniapp realizes global sharing of wechat applet and custom sharing button style
CEF下载,编译工程
Install local sources using yum
Development of electrical fire system
MySQL 数据库基础知识(系统化一篇入门)
顺利毕业[3]-博客系统 更新中。。。
Fundamentals of Electronic Technology (III)_ Integrated operational amplifier and its application__ Basic arithmetic circuit
MySQL data manipulation language DML common commands
Getting started with shell programming
Convert IP address to int
Comment la base de données mémoire joue - t - elle l'avantage de la mémoire?
端午节快乐!—— canvas写的粽子~~~~~