I have a controller like the following,
@RequestMapping(value = "rest/v1/tester")
public class TestController {
@RequestMapping(value = "/search", method = RequestMethod.GET)
public ResponseEntity<SampleResults> search(@ModelAttribute("criteria")SampleCriteria criteria) throws Exception {
SampleResults sampleResults = sampleService.search(criteria);
return new ResponseEntity<>(sampleResults, OK);
}
}
I have another controller like so,
@RequestMapping(value = "rest/v1/second")
public class SecondTestController {
@RequestMapping(value = "/search", method = RequestMethod.GET)
public ResponseEntity<SampleResults> search(@ModelAttribute("criteria")SampleCriteria criteria) throws Exception {
SampleResults sampleResults = secondsampleService.search(criteria);
return new ResponseEntity<>(sampleResults, OK);
}
}
The structure of my result is as follows:
public class SampleResults extends Results<SearchSummary, Sample> {
}
This extends from the result class:
public class Results<SUMMARY,RESULTS> {
private SUMMARY summary;
private List<RESULTS> results;
/*Constructors, getters and setters*/
}
Now the model that I am going to set into the results field is,
@JsonDeserialize(as = SampleImpl.class)
public interface Sample {
Long getId();
void setId(Long id);
String getName();
void setName(String name);
int getAge();
void setAge(int age);
}
public class SampleImpl implements Sample {
private Long id;
private String name;
private int age;
/* Getters and Setters */
}
Now for the TestController mentioned above, I would like to display all the fields in the json response, whereas in the SecondTestController I would like to mask (not show) the age attribute in the json response. How can I achieve this in spring. Any help greatly appreciated!