1

我有一个父类

public class Parent {

    @JsonProperty("ID")
    private int id;

    // getter and setter
}

和相应的子类

public class Child extends Parent {

    @Override
    @JsonIgnore
    public int getId() { 
        return id; 
    }
}

虽然该字段id应该为Parent其他子类序列化,但我不想将它包含在特定的子类Child中。但是,注释@JsonIgnore不会覆盖注释@JsonProperty,并且id在序列化Child.

有趣的是,它适用@JsonIgnoreProperties("ID")于类级别Child,但我想知道如何在方法级别完成它以及为什么我的方法不起作用。

我在 2.9.6 版中使用 Jackson。

4

0 回答 0