如何在循环引用中使用@JsonIdentityInfo?

如何在循环引用中使用@JsonIdentityInfo?,第1张

如何在循环引用中使用@JsonIdentityInfo?

似乎jackson-jr具有Jackson功能的一部分。

@JsonIdentityInfo
一定没有切入。

如果可以使用完整的Jackson库,则只需对问题中建议

ObjectMapper
@JsonIdentityInfo
注释使用标准并序列化对象即可。例如

@JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class, property="@id")public class A {}@JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class, property="@id")public class B {}

然后

A a = new A();B b = new B(a);a.setB(b);ObjectMapper mapper = new ObjectMapper();System.out.println(mapper.writevalueAsString(a));

会产生

{    "@id": 1,    "b": {        "@id": 2,        "a": 1    }}

其中嵌套

a
是通过引用根对象
@id



欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/zaji/5622888.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-15
下一篇2022-12-15

发表评论

登录后才能评论

评论列表(0条)

    保存