cancel
Showing results for 
Search instead for 
Did you mean: 

Swagger 3 does not respect @JsonView() for derived classes

New Member

Swagger 3 does not respect @JsonView() for derived classes

For example I have following data stricture:

class mainclass{

@JsonView({VIEW1.class, VIEW2.class})
private Animal someField;
}

class Animal {

}


class Cat extends Animal {

}

class Dog extends Animal {

}

class Tiger extends Cat {

}

class Wolf extends Dog {

}


And I defined 2 APIs that return mainclass: one API has @JsonView(VIEW1.class) and another one has @JsonView(VIEW2.class)

Each class in hierarchy has fields that must be displayed in VIEW1 only and fields for VIEW2 only.

Expected: Animal_VIEW1, Animal_VIEW2, Cat_VIEW1, Cat_VIEW2 etc.
Instead I get Cat, Tiger e t c with all fields without respect to view (on my mind they are introspected without view, so all fields are included)

How to fix this?

New Here?
Join us and watch the welcome video:
Watch the new Interview