@RequestBody in Spring Boot binds the body of an incoming HTTP request to a controller method parameter. Spring Boot auto-configures Jackson, so a JSON body is converted into your Java object with no extra setup. It is the standard way to receive data in POST, PUT and PATCH REST endpoints.
This article focuses on what Spring Boot adds on top of Spring MVC: auto-configured JSON handling, the validation starter, and the error responses you get when the body is wrong.
Adding spring-boot-starter-web brings in Spring MVC and Jackson. Boot then registers a MappingJackson2HttpMessageConverter and an ObjectMapper with sensible defaults. In Spring Boot 4 and Spring Framework 7 the default JSON stack moves to Jackson 3, but the controller code you write stays the same.
Defaults worth knowing:
LocalDate are supported through the JSR-310 module.You can change them with spring.jackson.* properties in application.properties.
A request with this body:
returns:
Records work as request bodies. A classic POJO with a no-argument constructor and getters and setters works as well.
Spring Boot reads the Content-Type header to choose the converter. JSON works out of the box. For XML bodies add the Jackson XML module:
Then a request with Content-Type: application/xml and a body such as <user><name>Jane</name><age>25</age></user> is bound to the same Java type. You can limit a method to one format with consumes:
A request with another content type then gets 415 Unsupported Media Type.
Add the validation starter:
Then annotate the type and the parameter:
An invalid body raises MethodArgumentNotValidException, which Spring Boot answers with 400. To return a structured error, handle it in a @RestControllerAdvice and produce a ProblemDetail (RFC 9457 problem details), which Spring supports natively since Spring Framework 6. Set spring.mvc.problemdetails.enabled=true to have Boot render standard errors that way.
Rename or ignore properties on the DTO with Jackson annotations:
The client now sends full_name. The same annotations control serialization when you return the object in a response.
| HTTP method | Path | Body | Meaning |
|---|---|---|---|
POST | /users | Full new resource | Create |
PUT | /users/{id} | Full replacement | Replace |
PATCH | /users/{id} | Only changed fields | Partial update |
Use a separate request record for each operation, and never bind the body directly to a database entity. This stops clients from setting fields such as id or role that they should not control.
Usually the Content-Type header is missing or the property names in the JSON do not match the Java fields. Check the header and the names, and confirm Jackson can construct the class.
The body is absent, malformed, or contains values of the wrong type, such as a string where an integer is expected. Spring returns 400 Bad Request.
Yes by default. Use @RequestBody(required = false) only when a request without a body is valid.
@RequestBody reads the request body into a parameter. @ResponseBody writes the return value to the response body.
In Spring Boot, @RequestBody uses the auto-configured Jackson converter to turn the request body into a Java object. Use records as request types, add spring-boot-starter-validation with @Valid for input checks, and use consumes to restrict formats. Wrong or missing content types and malformed JSON produce 415 and 400 responses.