intermediateException Handling & Validation
How does Bean Validation (`@Valid` + `@NotNull`/`@Size`) actually get triggered on a REST request?
Annotating a `@RequestBody` parameter with `@Valid` tells Spring MVC to run the object through the Bean Validation provider (Hibernate Validator) right after deserialization, checking every constraint annotation on its fields. If any fail, Spring throws `MethodArgumentNotValidException` before your controller method body even runs, which you then handle via `@ExceptionHandler` to shape the 400 response.
Ready to master this question?
Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.
Sign in to generate a response