本文介绍了Java对象图到JSON的转换,带有循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将Java对象图转换为具有循环依赖关系/周期的JSON?

How to convert a Java object graph to JSON, where the graph has circular dependencies / cycles?

推荐答案

有许多可以生成JSON的开源库.泽西岛可以打破循环依赖关系.对于其他人,您可能想谷歌搜索.

There are many open source libraries that can generate JSON. Jersey can break the circular dependencies. For others you might want to google.

  • Jersey (Use @JsonIgnore instead of @XmlTransient to break the circular dependency)
  • Gson (doesn't support circular references. there is a open defect created for this)
  • Jackson (Handle bi-directional references using declarative methods)
  • flexjson (claims it supports circular references)

这篇关于Java对象图到JSON的转换,带有循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 06:38