I am writing a Spring RESTful service which consumes JSON and performs some action. As the request contains a large number of parameters, I thought of mapping my request parameters to Java object using Spring's Jackson mapping.
My POJO
public class RequestInput {
private int id;
private String name;
// parameters follow
// getter and setter
}
My controller
@Controller
public class RequestController{
@RequestMapping(method=RequestMethod.POST, value="/rest/postRequest")
public void handleRequest(@RequestBody RequestInput input){
// code follows
}
}
Things work fine when the data is posted as
{"id" : 1, "name" : "ABCD"}
but when data is posted as
{"id" : 1, "first_name" : "ABCD"}
value of name in object is being returned as NULL
.
Can you please help me in understanding how I can map first_name in request to name param in Java POJO