当前位置:网站首页>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));
可以看到 现在成功了解决了循环引用这个问题
边栏推荐
- 在三线城市、在县城,很难毕业就拿到10K
- 【顺利毕业】[1]-游览 [学生管理信息系统]
- CEF下载,编译工程
- 2020-08-23
- 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)
- The third paper of information system project manager in soft examination
- 单片机职业发展:能做下去的都成牛人了,熬不动就辞职或者改行了
- 学习开发没有捷径,也几乎不存在带路会学的快一些的情况
- Exception handling of arm
猜你喜欢
Idea remote breakpoint debugging jar package project
我想各位朋友都应该知道学习的基本规律就是:从易到难
When you need to use some functions of STM32, but 51 can't realize them, 32 naturally doesn't need to learn
STM32 port multiplexing and remapping
STM32 external interrupt experiment
Nodemcu-esp8266 development (vscode+platformio+arduino framework): Part 5 --blinker_ MIOT_ MULTI_ Outside (lighting technology app + Xiaoai classmate control socket multiple jacks)
[csdn] C1 analyse des questions de formation Partie III Bar _ JS Foundation
Fundamentals of Electronic Technology (III)__ Chapter 1 resistance of parallel circuit
How does the memory database give full play to the advantages of memory?
Nr-prach: access scenario and access process
随机推荐
Successful graduation [3]- blog system update...
STM32 port multiplexing and remapping
Leetcode daily question (985. sum of even numbers after queries)
IDEA远程断点调试jar包项目
单片机职业发展:能做下去的都成牛人了,熬不动就辞职或者改行了
【22毕业季】我是毕业生yo~
当你需要使用STM32某些功能,而51实现不了时, 那32自然不需要学
Eight working modes of stm32gpio and chip naming rules
Matlab reads hexadecimal numbers and converts them into signed short
Basic knowledge of MySQL database (an introduction to systematization)
新系列单片机还延续了STM32产品家族的低电压和节能两大优势
Comment la base de données mémoire joue - t - elle l'avantage de la mémoire?
我想各位朋友都应该知道学习的基本规律就是:从易到难
307. Range Sum Query - Mutable
Shell logic case
內存數據庫究竟是如何發揮內存優勢的?
MySQL Data Definition Language DDL common commands
PRACH --- originator
PIP references domestic sources
Flink learning notes (IX) status programming