@RequestBody tells Spring MVC to read the HTTP request body and convert it into a Java object using an HttpMessageConverter. In a REST controller it is how a JSON (or XML) payload becomes a typed parameter, so you never parse the raw stream yourself. Combine it with @Valid to validate the payload before your method runs.
The annotation is part of org.springframework.web.bind.annotation and works the same in Spring MVC and Spring Boot. In Spring Boot 3 and later (Jakarta EE namespace), JSON conversion is handled by Jackson out of the box.
When a request reaches a handler method, Spring resolves each parameter. For a parameter marked @RequestBody, the RequestResponseBodyMethodProcessor takes over and does three things:
Content-Type header of the request.HttpMessageConverter that can read that media type into the parameter type.If no converter supports the content type, Spring answers with 415 Unsupported Media Type. If the body is malformed or cannot be mapped to the target type, it answers with 400 Bad Request (a HttpMessageNotReadableException internally).
The following controller accepts a JSON document and maps it to a Java record. Records work with Jackson 2.12 and later, and they make good request DTOs because they are immutable.
Send a request with curl:
The Content-Type: application/json header matters. Without it the request may be rejected with 415, because Spring cannot tell which converter to use.
Spring Boot registers converters based on what is on the classpath. The common ones are:
| Converter | Media type | Needs on the classpath |
|---|---|---|
JacksonJsonHttpMessageConverter / MappingJackson2HttpMessageConverter | application/json | Jackson (included by spring-boot-starter-web) |
MappingJackson2XmlHttpMessageConverter | application/xml | jackson-dataformat-xml |
StringHttpMessageConverter | text/plain and others | Always present |
ByteArrayHttpMessageConverter | application/octet-stream | Always present |
FormHttpMessageConverter | application/x-www-form-urlencoded | Always present |
The exact Jackson converter class name depends on your Spring version (Spring Framework 7 adds Jackson 3 based converters), but the behaviour is the same: the request Content-Type selects the converter.
You can restrict what a method accepts with the consumes attribute:
Add spring-boot-starter-validation and put @Valid (or @Validated) next to @RequestBody. When validation fails, Spring throws MethodArgumentNotValidException, which by default produces a 400 response. A global handler lets you return a consistent error format.
By default the body is required. If a client sends none, Spring returns 400. Set required = false to receive null instead:
You can bind collections and generic types, and you can read the body as a plain String or byte[] when you need the raw payload (for example to verify a webhook signature):
@RequestBody parameter is allowed per method, because the request stream can be read once.@RequestBody does not work for HTML form posts with a form encoding such as multipart/form-data. Use @ModelAttribute, @RequestParam or @RequestPart for those.GET requests normally have no body, so @RequestBody on a GET handler is a design smell. Use query parameters.spring.jackson.deserialization.fail-on-unknown-properties) to match your API's tolerance for extra fields.@ResponseBody, which writes the return value to the response. @RestController already includes it.@RequestParam reads query-string or form parameters, one value at a time. @RequestBody reads the whole request body and deserializes it into an object.
The request Content-Type has no matching converter, often because the header is missing or is text/plain while the endpoint expects application/json. Send the correct header or widen consumes.
Yes. Add jackson-dataformat-xml (or JAXB support) and send Content-Type: application/xml. Spring selects the XML converter automatically.
Yes. It is a Spring MVC feature. In plain Spring you must enable @EnableWebMvc (or use Spring Boot's auto-configuration) and add a JSON library such as Jackson so a suitable converter is registered.
@RequestBody binds the HTTP request body to a method parameter through HttpMessageConverters chosen by the Content-Type header. Pair it with a DTO or record, add @Valid for validation, handle errors with @RestControllerAdvice, and remember it reads the stream only once and is meant for POST, PUT and PATCH style requests.