Special annotation, @JsonView exists for that. Imagine that you have a PersonDto class which contains two properties: name and age. You want to show name every time but age only for one endpoint. To enable that, we must first define a class, such as PersonWithAgeView. After, we must decorate age property with @JsonView:
public class PersonDto { // ... @JsonView(PersonWithAgeView.class) private int age; }
After, we must do the same with endpoint(s) which should contain age property in the response:
public class PersonController { @GET @Path("extended/{id}") @JsonView(PersonWithAgeView.class) public PersonDto getExtendedPerson(@PathParam("id") int id) { // } } }