@RequestBody tells Spring MVC to read the HTTP request body and convert it into the annotated method parameter. Spring picks an HttpMessageConverter based on the Content-Type header, so a JSON body becomes a Java object without any manual parsing. You use it on POST, PUT and PATCH endpoints that receive structured data.
The annotation lives in org.springframework.web.bind.annotation. It works the same way in plain Spring MVC and in Spring Boot, and in Spring Boot 3 and later it pairs with the jakarta.validation annotations for input validation.
When a request reaches a controller method with a @RequestBody parameter, Spring does three things:
Content-Type request header, for example application/json.HttpMessageConverter that can read that type into the parameter's Java type. With Jackson on the classpath, application/json is handled by the Jackson converter.If the body is missing, malformed, or has an unsupported content type, Spring rejects the request before your code runs.
Since Java 16 you can use a record as the request type. Jackson 2.12 and later supports deserializing records, which removes the getter and setter boilerplate.
Send a request:
The response body is:
A class with a default constructor and setters works too. Use a record for immutable request DTOs and keep them separate from your JPA entities.
@RequestBody only converts data. To reject bad input, add Bean Validation annotations to the type and @Valid to the parameter.
This needs spring-boot-starter-validation on the classpath. When validation fails, Spring throws MethodArgumentNotValidException and answers with 400 Bad Request by default. In Spring Boot 2.x the package is javax.validation instead of jakarta.validation.
Which formats work depends on the converters present:
| Content-Type | Needs |
|---|---|
application/json | Jackson (included in spring-boot-starter-web) |
application/xml | jackson-dataformat-xml on the classpath |
text/plain | Built-in string converter, parameter type String |
application/octet-stream | Built-in converter, parameter type byte[] |
To control the JSON shape, annotate the DTO with Jackson annotations:
Now the client sends full_name, while your code uses name. Spring Boot's default ObjectMapper is already configured to ignore unknown properties, but you can set spring.jackson.deserialization.fail-on-unknown-properties=true if you want strict input.
| Annotation | Reads from | Typical use |
|---|---|---|
@RequestBody | The whole request body | JSON or XML payloads |
@RequestParam | Query string or form field | Simple scalar values |
@ModelAttribute | Form fields or query parameters bound to an object | HTML form submission |
@PathVariable | The URL path | Resource identifiers |
A request has only one body, so a method can have at most one @RequestBody parameter.
415 Unsupported Media Type: the client did not send a Content-Type that a converter supports. Send Content-Type: application/json.400 Bad Request with HttpMessageNotReadableException: the body is empty (@RequestBody is required by default) or the JSON is malformed or has the wrong types.null: the DTO has no accessible setters or constructor Jackson can use, or the property names do not match.@RequestBody(required = false) only when an empty body is a valid request.Technically the servlet container allows a body on GET, but the HTTP specification gives it no meaning and many clients and proxies drop it. Use query parameters for GET.
Yes. Use List<CreateUserRequest> as the parameter type and send a JSON array. Spring handles the generic type through Jackson.
Yes. @RestController only adds @ResponseBody to every method, and @RequestBody works in either kind of controller.
Declare the parameter as String or byte[], or use HttpEntity<String> if you also need the headers.
@RequestBody binds the request body to a method parameter using the HttpMessageConverter that matches the Content-Type. Use records as request types, add @Valid to enforce constraints, and keep DTOs separate from entities. Most failures come from a missing or wrong Content-Type or from a body that does not match the target type.