Consider this Spring Boot Request DTO and controller method:
public record UserRequest(String name, int age) {}@PostMapping("/user")
public ResponseEntity createUser(@RequestBody UserRequest request) {
return ResponseEntity.ok("User " + request.name() + " is " + request.age() + " years old.");
} If the JSON {"name":"Alice","age":30} is sent, what will the response body be?
Records automatically map JSON fields to constructor parameters by name.
The JSON fields match the record components exactly, so Spring Boot deserializes correctly. The response concatenates the values properly.
Choose the correct Java record declaration for a Request DTO with fields email (String) and subscribed (boolean):
Records use parentheses with comma-separated components.
Option D uses the correct syntax for Java records. Option D uses semicolon instead of comma. Option D is not a record syntax. Option D uses boxed Boolean which is valid but not the exact requested type.
Given this Request DTO and controller method:
public record ProductRequest(String productName, int quantity) {}@PostMapping("/product")
public ResponseEntity addProduct(ProductRequest request) {
return ResponseEntity.ok("Added " + request.productName() + ", qty: " + request.quantity());
} When sending JSON {"productName":"Pen","quantity":10}, the server returns HTTP 400. Why?
Spring Boot needs an annotation to know where to get the data from.
Without @RequestBody, Spring tries to bind from form data or query parameters, not JSON body, causing HTTP 400 error.
Given this Request DTO record and JSON input:
public record PersonRequest(String name, Integer age) {}JSON sent: {"name":"Bob"}
What will be the value of age() in the deserialized object?
Consider the difference between primitive and wrapper types.
Since age is Integer (wrapper), missing JSON field results in null. If it were int (primitive), it would default to 0.
Choose the correct statement about Java records used as Request DTOs in Spring Boot:
Think about how records handle data and immutability.
Records are immutable data carriers with final fields and canonical constructors, making them ideal for Request DTOs without needing setters or no-arg constructors.