SPRING CONCEPTS

Request-body binding

Spring Concepts / Request-body binding

@RequestBody binds an HTTP body to a Java method argument.

Understand the idea

For JSON, an HTTP message converter parses the body into the requested DTO. @Valid then applies its constraints. Syntactically malformed JSON fails during parsing; valid JSON with invalid values fails validation.

A concrete example

create(@Valid @RequestBody TodoRequest request)

In the application

The REST and personal controllers accept JSON requests using TodoRequest; Postman sends Content-Type: application/json.

JSON bodies are different from HTML form fields. A form-data request does not automatically match this JSON contract.

Related concepts

Read the official documentation ↗
Java 21 · Spring Boot 4.1.1 · Edupoly