1

There is a class annotated with @JsonIgnoreProperties (base class) and some subclasses extending it. Now, in one Post API, the request body (a map) could be type of any of the subclasses. I have written code to create instance of base class based on an additional type property (using object mapper). But since my base and subclasses are annotated with @JsonIgnoreProperties, even if I'm sending incorrect pair of properties and data, mapping is not failing.

How do I fail this? There are other APIs using this base and subclass and hence I don't want to tamper with the existing classes. Is there a way to nullify this ignore check or something during the switch case conversion?

João Dias
  • 16,277
  • 6
  • 33
  • 45
N.Rajal
  • 105
  • 2
  • 17
  • I think your main problem is that you are trying to reuse a class for something that it was not meant for. Maybe the solution is to not reuse that class and create a new one that fit the need instead of forcing the hand of the framework. Interesting read for your problem: https://en.wikipedia.org/wiki/Liskov_substitution_principle – litelite Oct 06 '21 at 14:38
  • Right, that was another thing that crossed my mind. However the APIs I'm writing are part of a pre-existing controller and the classes are being used in other APIs, so I also want to maintain consistency. I'm not sure if it would be a good idea to have same set of classes and subclasses (defining same real world object) with the difference being an annotation on top of them in the same controller. – N.Rajal Oct 07 '21 at 07:28

0 Answers0