@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 を同じクラスで使用しても、最初の結果が期待されます。私は何を間違っていますか?