0

I am trying to find how @RequestBody is work

suppose i have post request with input json like this

{
"firstName" : "abcdf",
"email" : "abc@xyz.com",
"phoneNumber" :"0000000000"
}

but my java class have variable like

class Student{

private String fullName;
private String emailAddress;
private int mobileNumber;

// getter and setter here
}

my Rest End point is like.

@RequestMapping(value = "/saveStudentInfo", method = RequestMethod.Post)
public setStudentInfo(@requestBody Student student){

return studentService.save(student);
}

So What i do if my json veriable and java class variable is different is there any @annotation is there that i can use in Pojo class so it can map with different veriable name

Jens
  • 60,806
  • 15
  • 81
  • 95
harkesh kumar
  • 734
  • 5
  • 27
  • Take a look at [this](https://stackoverflow.com/a/29746495/3669624), you will find what you need. – cнŝdk Oct 10 '18 at 08:11

1 Answers1

0

You can use @JsonProperty("<json-name>") annotation for it.

For e.g.

class Student {

    @JsonProperty("firstName")
    private String fullName;

    public String getFullName() {
        return fullName;
    }

    public void setFullName(String fullName) {
        this.fullName = fullName;
    }

}
S.K.
  • 3,337
  • 2
  • 13
  • 27