Which annotation reads a JSON request body into a Java object?
Options
@PathVariable@RequestParam@RequestBody(Correct option)@ResponseBody
Answer
@RequestBody
Why
@RequestBody tells Spring to read the HTTP body (usually JSON) and convert it into the Java parameter with Jackson.
@RequestParam reads query parameters (/search?name=ana), @PathVariable reads parts of the path.
@ResponseBody is the opposite direction (object to body); @RestController already applies it to all methods.
@PostMapping
public ResponseEntity<User> create(@Valid @RequestBody CreateUserRequest req) {
User created = userService.create(req);
return ResponseEntity.status(HttpStatus.CREATED).body(created); // 201
}Remember
Body = @RequestBody. Query = @RequestParam. Path = @PathVariable.