Overriding @jsonIgnore in subclass

jackson, java, json

Solution

What you want in the Child class is not `@JsonProperty` but instead `@JsonIgnore(false)`.

Problem

I have a class Parent ``` public class Parent { private int id; @JsonIgnore int getId() {} void setId(int id) {} } ``` I have a subclass which is derived from Parent ``` public class Child extends Parent { @JsonProperty // just to explicitly tell jackson to serialize this @Override int getId() {} @Override void setId(int id) {} } ``` I actually don't want the id property to be serialized when an object of Parent is returned but it should be serialized when an object of Child class is returned. I think if Parent was an Interface, overriding the visibility would work, but I am not sure if the behavior is the same with superclass. Is there a simple solution for this? I would really appreciate your answers. Tx.

Original source