Jackson @jsonidentityinfo改变了原始数据结构

Shu*_*uai 5 json circular-reference jackson jsonidentityinfo

我有2个以下的循环引用类,为了方便,我没有放入getter和setter

@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "i")
public class A{
    int i;
    B b1;
    B b2;
}

@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "i")
public class B {
    int i;
    AI a;
}
Run Code Online (Sandbox Code Playgroud)

如果A.b1和A.b2引用同一个B对象,我得到了序列化的json,如下所示:

 {
  "i": 1,
  "b1": {
    "i": 2,
    "a": 1
  },
  "b2": 2
}
Run Code Online (Sandbox Code Playgroud)

但我的预期结果是:

 {
  "i": 1,
  "b1": {
    "i": 2,
    "a": 1
  },
  "b2": {
    "i": 2,
    "a": 1
  }
}
Run Code Online (Sandbox Code Playgroud)

我检查了jackson的源代码看起来像以前使用的对象的jackson store id/reference,如果任何其他对象使用相同的引用,那么它将使用id而不是序列化整个对象,如果对象保持在同一个循环链中,那就好了,但是如果他们不会停留在相同的链条中然后就像我的例子所示那样奇怪.

有人可以通过@identityinfo注释帮助我获得预期的结果吗?