
似乎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。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)