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

ここでは明らかに間違っているものは何も見当たらないので、バグを見つけた可能性があります。タイプとID情報の組み合わせは処理が少し難しいため、意図したとおりに機能しないエッジケースが存在する可能性があります。そのため、Github Issue Trackerでバグを報告できますか?

于 2013-02-25T19:36:22.457 に答える