@RequestBody tells Spring MVC to read the HTTP request body and convert it into a Java object that is passed to your controller method. Spring picks an HttpMessageConverter based on the request's Content-Type header, so a JSON body is turned into your type by Jackson, and the result arrives as an ordinary method argument. It is the standard way to receive JSON in POST, PUT and PATCH endpoints of a REST API.
The reverse direction, converting a return value into the response body, is handled by @ResponseBody, which @RestController applies to every method.
When a request reaches a handler method with a @RequestBody parameter, Spring performs these steps:
Content-Type header, for example application/json.MappingJackson2HttpMessageConverter in Spring Boot.If no converter supports the content type, Spring answers 415 Unsupported Media Type. If the body is missing or malformed, it answers 400 Bad Request.
Jackson can deserialize Java records, which makes them a compact request model:
A client sends:
Spring builds a CreateUserRequest with those values. Because the parameter is also marked @Valid, the Bean Validation constraints are checked before the method runs. Add spring-boot-starter-validation to enable them.
When validation fails, Spring raises an exception instead of calling your method, and the default response is 400 Bad Request. In current Spring Framework versions this is a MethodArgumentNotValidException for a @Valid @RequestBody argument, or a HandlerMethodValidationException when method validation applies. You can return a clean error body with a @RestControllerAdvice:
An unreadable body, such as broken JSON, raises HttpMessageNotReadableException, which Spring also maps to 400 by default.
@RequestBody is not limited to custom classes:
| Parameter type | Use |
|---|---|
| Record or POJO | Structured JSON mapped by Jackson |
List<T> or Map<String, Object> | Arrays and free-form JSON objects |
String | Raw body text |
byte[] | Binary payloads |
Optional<T> | Body may be absent when required = false |
By default @RequestBody is required, so an empty body returns 400. Use @RequestBody(required = false) when the body is optional. A method can have only one @RequestBody parameter, because the body stream can be read only once.
Content-Type: application/json, which causes 415.@RequestBody on a GET request. Browsers and many clients do not send bodies on GET, so use query parameters instead.@RequestBody for HTML form posts. Form data (application/x-www-form-urlencoded) is bound with @ModelAttribute or @RequestParam, not @RequestBody.id or role.@RequestBody converts the whole request body, usually JSON, into one object. @RequestParam reads a single query-string or form field by name.
@RequestBody converts the incoming request into a Java object, and @ResponseBody converts the returned Java object into the response body. @RestController already implies @ResponseBody.
Yes, if an XML converter is on the classpath, for example Jackson's XML module, and the client sends an XML content type. The same annotation works with any registered HttpMessageConverter.
Bind it to Map<String, Object> or JsonNode. Validate the content yourself, because bean validation annotations have nothing to check on a generic map.
@RequestBody binds the HTTP request body to a method parameter using the message converter that matches the Content-Type. Pair it with @Valid and a dedicated record or class, handle errors with @RestControllerAdvice, and remember it is for JSON-style bodies, not for form submissions or GET requests.