I want to exclude name and age from my response, but When I receive the JSON payload request I need name and age field - after my business logic, I want to send status and message as part of JSON response. name and age should exclude from that. How can I achieve this in java?
public class Sample {
private String name;
private String age;
private String status;
private String message;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
}
My Controller class:
@PostMapping(path = "/testApp", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Object> test(@RequestBody Sample sample) {
Sample response = myService.calculate(sample);
return new ResponseEntity<Object>(response, HttpStatus.OK);
}
My Request
{
"name": "Mark",
"age": "48"
}
My Response
{
"status": "200",
"message": "success"
}