3

@JsonIdentityInfo 按预期使用以下类:

基类:

@JsonIdentityInfo(generator =  ObjectIdGenerators.PropertyGenerator.class, property = "uuid")
public class TestEntityBas {
    @JsonProperty
    public String uuid = "0001";
}

子类:

public class TestEntityGoa extends TestEntityBas  {
    @JsonProperty
    public String texten = "This is text!";
}

容器类:

public class TestEntity {
    @JsonProperty
    String stringer = "Hej hopp!";

    @JsonIdentityReference(alwaysAsId = true)
    public TestEntityGoa goa = new TestEntityGoa(); 
}

结果如预期:

{"stringer":"Hej hopp!","goa":"0001"}

当我像这样将@JsonTypeInfo 添加到基类时:

@JsonTypeInfo(use=JsonTypeInfo.Id.CLASS, include=JsonTypeInfo.As.PROPERTY, property="@class")
@JsonIdentityInfo(generator =  ObjectIdGenerators.PropertyGenerator.class, property = "uuid")
public class TestEntityBas {
    @JsonProperty
    public String uuid = "0001";
}

现在整个 TestEntityGoa 像这样被序列化:

{"stringer":"Hej hopp!","goa":{"@class":"com.fodolist.model.TestEntityGoa","uuid":"0001","texten":"This is text!"}}

即使我在同一类中使用@JsonTypeInfo 和@JsonIdentityInfo,我也希望得到第一个结果。我究竟做错了什么?

4

1 回答 1

1

我在这里看不到任何明显的错误,所以你可能发现了一个错误。类型和身份信息的组合处理起来有点棘手,因此可能存在尚未按预期工作的边缘情况,那么您能否为此在 Github 问题跟踪器中提交错误?

于 2013-02-25T19:36:22.457 回答