2013-02-23 83 views
3

@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

回答

1

我在這裏看不到任何明顯的錯誤,所以你可能發現了一個錯誤。類型和身份信息的組合有點棘手,因此可能存在尚未按預期工作的邊緣情況,那麼您是否可以在Github問題跟蹤器上爲此提交一個錯誤?

相關問題