Quick revision
The short answer
A @RequestBody parameter is resolved by RequestResponseBodyMethodProcessor, which walks the registered HttpMessageConverters and picks the first one that can read the request's Content-Type into the parameter's type, for example the Jackson converter for application/json. RequestBodyAdvice beans can act before and after the body is read, and validation runs afterwards when the parameter has @Valid or @Validated. We change the process by customising converters through WebMvcConfigurer or, in Spring Boot, by declaring converter beans or tuning Jackson.
What to remember
In this answer, we followed a @RequestBody from bytes to object. RequestResponseBodyMethodProcessor picks the first HttpMessageConverter that can read the Content-Type into the target type, RequestBodyAdvice runs before and after the read, and validation runs last when @Valid or @Validated is present. Each failure, 415, unreadable body or invalid object, belongs to one step, and each step has its own extension point: Jackson settings and converter beans in Boot, extendMessageConverters in WebMvcConfigurer, RequestBodyAdvice for cross-cutting body logic, and validators and groups for the checks.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
A @RequestBody parameter is resolved by RequestResponseBodyMethodProcessor, which walks the registered HttpMessageConverters and picks the first one that can read the request's Content-Type into the parameter's type, for example the Jackson converter for application/json. RequestBodyAdvice beans can act before and after the body is read, and validation runs afterwards when the parameter has @Valid or @Validated. We change the process by customising converters through WebMvcConfigurer or, in Spring Boot, by declaring converter beans or tuning Jackson.
Why this question is asked
Most of the time @RequestBody just works, which is exactly why problems with it are confusing: a 415 Unsupported Media Type, a date that will not parse, or an unknown field that is silently ignored. Each of these has a precise place in the pipeline where it happens and a precise place where we can change it. Interviewers ask this to see whether we can debug and extend the request body handling instead of guessing. In this answer, we will recap what a message converter is, follow one request body from bytes to object, see where advice and validation fit, and then go through the places where we can customise each step.
1A Quick Recap of Message Converters
An HttpMessageConverter turns the bytes of an HTTP body into a Java object, and a Java object back into bytes. Each converter declares which media types it supports and which Java types it can handle. Spring MVC registers a list of them: one for byte arrays, one for strings, one for form data, one for JSON using Jackson, and others depending on what is on the classpath, such as XML or Protobuf.
The media type of a request body comes from its Content-Type header. A request with Content-Type: application/json and a JSON body will be read by the converter that says it can read application/json into the target type.
2Following One Request Body Step by Step
Take a controller method create(@Valid @RequestBody OrderRequest req) and a POST with a JSON body. RequestMappingHandlerAdapter asks its argument resolvers who supports this parameter. RequestResponseBodyMethodProcessor does, because the parameter has @RequestBody. It is called a processor because the same class also writes @ResponseBody return values.
The processor reads the Content-Type header; if there is none, it assumes application/octet-stream. Then it loops over the converters in order and asks each one whether it can read OrderRequest from application/json. The Jackson converter answers yes. Before reading, the processor calls beforeBodyRead on every RequestBodyAdvice that applies. Then the converter reads the stream and Jackson builds the object. Then afterBodyRead is called, and the result can even be replaced. If the body was empty, handleEmptyBody is called instead, and for a required body that ends in an error.
Finally, because the parameter has @Valid, the processor creates a data binder for the object and runs Bean Validation on it. If any constraint fails, it throws MethodArgumentNotValidException, which becomes a 400 response. Only then is the controller method invoked.
- Read Content-Typemissing means application/octet-stream
- Some converter can read this type and media type?Yesuse the first one that canNo415 Unsupported Media Type
- RequestBodyAdvice.beforeBodyReadmay wrap or replace the input
- Converter reads the bodyJackson builds
OrderRequest - RequestBodyAdvice.afterBodyReadmay change the object
- @Valid or @Validated present?Yesrun Bean ValidationNopass the object to the method
- Invoke create(req)only valid objects reach here
7 steps in order. Play them, or step through them one at a time.
Notice that each failure comes from a different step: no converter for the media type gives 415, a converter that cannot parse the bytes gives 400 HttpMessageNotReadableException, and a parsed object that breaks a constraint gives 400 MethodArgumentNotValidException. Knowing the step tells us where to look.
3Where RequestBodyAdvice Fits
RequestBodyAdvice is an interface for code that needs to see every request body for a set of controllers. We implement it, usually by extending RequestBodyAdviceAdapter, and annotate the class with @ControllerAdvice, optionally limited by package or annotation. Its supports() method decides whether it applies to a given parameter and converter.
Typical uses are decrypting a body before Jackson sees it, recording the raw body for an audit, or normalising a field after the object is built.
The advice runs inside the converter step, so it sees bodies only for @RequestBody and HttpEntity parameters. It does not see form posts bound with @ModelAttribute, which go through data binding instead.
4Changing the Converters
The most common change is not a new converter but different Jackson settings. In Spring Boot we use properties such as spring.jackson.deserialization.fail-on-unknown-properties=true, or a customizer bean that adjusts the ObjectMapper builder. Boot builds its JSON converter from that configured mapper, so every endpoint picks up the change. Spring Framework 7 and Spring Boot 4 move to Jackson 3 with new class and customizer names, so check your version for the exact types.
To add a converter, for example for CSV, Spring Boot lets us declare it as a bean, and Boot adds it to the list, ahead of the defaults. Without Boot, or when we need to reorder, we implement WebMvcConfigurer.extendMessageConverters, which receives the already configured list. We avoid configureMessageConverters for this, because adding anything there stops Spring from registering its default converters.
We only need one of the two approaches. Order matters because the first converter that can read the type and media type wins, so a specific converter should come before a generic one.
5Where Validation Happens and How to Change It
Validation is the last step and is controlled by annotations. @Valid triggers standard Bean Validation; @Validated does the same and also allows validation groups, such as Create.class for rules that apply only when creating. The validator is the one Spring Boot configures from Hibernate Validator, and we can supply our own Validator bean or register a custom constraint.
If we want to handle validation errors ourselves, we can add an Errors or BindingResult parameter directly after the @RequestBody parameter; then the method runs and inspects the errors instead of Spring throwing. For APIs it is usually cleaner to let the exception propagate and map it once, in a @RestControllerAdvice, to a ProblemDetail response.
6Follow-up questions
What decides which converter is picked when several could read the body?
The order of the converter list. The processor asks each converter in turn whether it can read the target type from the request's media type, and the first that says yes is used. That is why a custom converter that claims to read all media types can accidentally take over JSON requests if it is placed first.
Why do unknown JSON fields not cause an error in Spring Boot?
Because Spring's Jackson builder, which Boot uses, disables Jackson's FAIL_ON_UNKNOWN_PROPERTIES by default, so extra fields are ignored. That is friendly for evolving clients. If we want strict input, we enable it with spring.jackson.deserialization.fail-on-unknown-properties=true, and clients then get a 400 for unexpected fields.
Is @RequestBody required by default, and what if the body is empty?
Yes, required is true by default. An empty body then fails with HttpMessageNotReadableException and a 400 response. With @RequestBody(required = false), an empty body gives null instead, and RequestBodyAdvice.handleEmptyBody can supply a default.
7Conclusion
In this answer, we followed a @RequestBody from bytes to object. RequestResponseBodyMethodProcessor picks the first HttpMessageConverter that can read the Content-Type into the target type, RequestBodyAdvice runs before and after the read, and validation runs last when @Valid or @Validated is present. Each failure, 415, unreadable body or invalid object, belongs to one step, and each step has its own extension point: Jackson settings and converter beans in Boot, extendMessageConverters in WebMvcConfigurer, RequestBodyAdvice for cross-cutting body logic, and validators and groups for the checks.
Open with
A @RequestBody parameter is handled by RequestResponseBodyMethodProcessor, which is one of the argument resolvers RequestMappingHandlerAdapter consults. It reads the Content-Type, defaulting to application/octet-stream, and walks the list of HttpMessageConverters asking which one can read that media type into the parameter type.
Then, if they want more
For application/json that's the Jackson converter. If none can, we get a 415. Before and after the read it calls any RequestBodyAdvice beans that apply, so I can decrypt or audit the body, or adjust the object afterwards. If the JSON can't be parsed, that's HttpMessageNotReadableException and a 400.
Then, if the parameter has @Valid or @Validated, it runs Bean Validation and throws MethodArgumentNotValidException on failures, also a 400, unless I put a BindingResult right after the parameter. As for changing it: most often I just change Jackson, through spring.jackson properties or a customizer bean, and Boot builds the converter from that mapper.
To add a converter, in Boot I declare an HttpMessageConverter bean, or I use extendMessageConverters in a WebMvcConfigurer. I'd avoid configureMessageConverters, because adding anything there stops the defaults being registered. And order matters, because the first converter that can read the type wins. Validation I change with groups through @Validated, custom constraints, or a custom validator.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Spring Boot 4, Spring Framework 7
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Framework reference, Spring Web MVC
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "How is a @RequestBody parameter turned into a Java object, and where can you change the...": https://scrivio-interview-library.netlify.app/spring-boot/mvc-architecture/209e51196a/