Bird
0
0

Given the following DTO and controller method, what will happen if the client sends a request with an empty email field?

medium📝 component behavior Q13 of 15
Spring Boot - Request and Response Handling
Given the following DTO and controller method, what will happen if the client sends a request with an empty email field? public class UserDTO { @NotBlank private String email; // getters and setters } @PostMapping("/users") public ResponseEntity createUser(@Valid @RequestBody UserDTO user) { return ResponseEntity.ok("User created"); }
AThe request will be ignored silently
BThe request will succeed and return "User created"
CThe server will throw a NullPointerException
DThe request will fail validation and return a 400 Bad Request with an error message
Step-by-Step Solution
Solution:
  1. Step 1: Understand @NotBlank validation

    The @NotBlank annotation requires the field to be non-null and contain at least one non-whitespace character.
  2. Step 2: Analyze the empty email input

    An empty string fails @NotBlank validation, so Spring Boot will reject the request and return a 400 error with validation details.
  3. Final Answer:

    The request will fail validation and return a 400 Bad Request with an error message -> Option D
  4. Quick Check:

    @NotBlank empty input causes 400 error [OK]
Quick Trick: Empty strings fail @NotBlank, causing 400 errors [OK]
Common Mistakes:
  • Assuming empty strings pass validation
  • Expecting NullPointerException instead of validation error
  • Thinking server ignores invalid input

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes