Request Body

The request body is the data a client sends inside a POST or PUT request, usually as JSON. @RequestBody tells Spring to read that JSON and convert it into a Java object automatically, using the Jackson library (this is called deserialization). It is used for sending structured data such as registration forms, orders, or profile updates, which is too large or too private for the URL. JSON keys are matched to the Java field names, nested JSON objects become nested Java objects, and JSON arrays become lists.

Types

  • Object binding: @RequestBody RegisterRequest request (JSON to a DTO class).
  • Validated body: @Valid @RequestBody ... with @NotBlank, @Email, @Min and similar rules.
  • Collection body: @RequestBody List<Student> students for a JSON array.
  • Generic body: @RequestBody Map<String, Object> data when there is no fixed structure.
  • Raw text body: @RequestBody String body.
  • Content type: consumes = "application/json" restricts what the endpoint accepts.
Scroll to Top