Forum Discussion

VitalyM's avatar
VitalyM
New Member
5 years ago

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?

No RepliesBe the first to reply