I am having two Spring Rest service create-employee and create-staff like as shown below
create-employee
@RequestMapping(value="/create-employee", method = RequestMethod.POST, consumes = "application/json")
public ResponseEntity<Void> createEmployee(final @RequestBody User user) {
    try {
        // employee createion logic
    } catch (Exception exception) {
        log.error("Exception in createEmployee:"+exception.getMessage());
        return new ResponseEntity<>(HttpStatus.FORBIDDEN);
    }
}
create-staff
@RequestMapping(value="/create-staff", method = RequestMethod.POST, consumes = "application/json")
public ResponseEntity<Void> createStaff(final @RequestBody User user) {
    try {
        // staff creation logic
    } catch (Exception exception) {
        log.error("Exception in createStaff:"+exception.getMessage());
        return new ResponseEntity<>(HttpStatus.FORBIDDEN);
    }
}
For both the services I am using a dto named User like as shown below:
public class User {
    @JsonProperty("employeeName")
    private String name;
    @JsonProperty("age")
    private Integer age;
    @JsonProperty("managerName")
    private String headName;
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public Integer getAge() {
        return age;
    }
    public void setAge(Integer age) {
        this.age = age;
    }
    public String getHeadName() {
        return headName;
    }
    public void setHeadName(String headName) {
        this.headName = headName;
    }
}
Now the issue is that for both create-employee and create-staff since I am using User.java as the request body. The posting json body looks like this
{
 "employeeName" : "string",
 "age" : "integer",
 "managerName" : "string"
}
but actually what I want is that for create-staff service I would like to have the json body as below
{
 "staffName" : "string",
 "age" : "integer",
 "managerName" : "string"
}
and create-staff service I would like to have the json body as below
{
 "employeeName" : "string",
 "age" : "integer",
 "managerName" : "string"
}
But for both the services I need to use the same User.java dto but with different JsonProperty for the two services
Can anyone please hep me on this
 
    