11

Is there any way I can tell Jackson to ignore properties from parent class while serializing a child class?


    class Parent{
      private String parentProperty1;
      private String parentProperty2;
      //getter setter
    }

    @IgnoreParentProperties // I am expecting something like this
    class Child extends Parent{
      private String childProperty1;
      //getter setter
    }

Christian Neverdal
  • 5,655
  • 6
  • 38
  • 93
Moinul Hossain
  • 2,176
  • 1
  • 24
  • 30

2 Answers2

9

In addition to Views that work well, you can also use @JsonIgnoreProperties to list names of properties to ignore; this can include parent properties as well.

StaxMan
  • 113,358
  • 34
  • 211
  • 239
5

Define & use a JSON view which omits the inherited fields.

Matt Ball
  • 354,903
  • 100
  • 647
  • 710