1

I have a parent class

public class Parent {

    @JsonProperty("ID")
    private int id;

    // getter and setter
}

and a corresponding subclass

public class Child extends Parent {

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

While the field id should be serialized for Parent and other subclasses, I do not want to include it in the specific subclass Child. However, the annotation @JsonIgnore doesn't override the annotation @JsonProperty and the id is also included when serializing the Child.

Interestingly, it works with @JsonIgnoreProperties("ID") at class level of Child, but I would like to know how it can be accomplished at method level and why my approach doesn't work.

I am using Jackson in version 2.9.6.

stan
  • 95
  • 2
  • 8

0 Answers0