Showing posts with the label @RequestBody

Spring @RequestBody Annotation Example

In this section we will learn about  @RequestBody  Annotation.   @RequestBody   annotation is used to indicating a method parameter should be bind to the body of the HTTP request. Internally, this annotation uses HTTP Message converters to convert the body of HTTP requests to domain objects.  "HTTP message converters are used to convert HTTP request body (either JSON or XML) to Java objects and java objects back to XML or JSON for composing HTTP response" { "name" : "john" , "email" : "" } Assume that we are sending this JSON in the request body, now inside the controller, we can bind this JSON data to a domain object. @PostMapping ( "/users" ) public void saveUser ( @RequestBody User user ) { } Now this will happen with the help of Jackson API which is present in the classpath. Spring would convert the incoming JSON to a User object from the request body (because we added the  @RequestBody  annotat