为什么@JsonTypeInfo不能和@JsonIdentityInfo一起使用?

问题描述:

@JsonIdentityInfo工作与以下类预期:为什么@JsonTypeInfo不能和@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在同一个类中。我究竟做错了什么?

+0

一个错误在https://github.com/FasterXML/jackson-databind/issues/178 – 2013-02-26 09:32:14

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