我正在尝试使用 Jackson JSON 序列化 Javaparser 对象,但它非常复杂,因为它是第三方库(我无法更改/注释代码)并且其中存在循环依赖关系。
我的项目结构如下:
一个对象Analysis
包含一些WrappedNode
可能相互引用的列表。每个都WrappedNode
包含一个 JavaParser CallableDeclaration
。
当我尝试映射我的Analysis
时,我遇到了一个错误:
JsonMappingException: Infinite recursion (StackOverflowError) (through reference chain: com.github.javaparser.metamodel.PropertyMetaModel["containingNodeMetaModel"]->com.github.javaparser.metamodel.SimpleNameMetaModel["declaredPropertyMetaModels"]->java.util.ArrayList[0]->com.github.javaparser.metamodel.PropertyMetaModel["containingNodeMetaModel"]...
所以,为了摆脱无限递归,我知道我必须使用@JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class, property="@id")
,我在我的课堂上做过,但我认为我还应该使用Mix-in annotations 对WrappedNode
JavaParser 类进行注释。
问题是字段多,类多,不知道要注释哪些。
谢谢你的帮助 !