Bird
0
0

Given this Spring Boot controller method snippet, what will be the HTTP response status if validation fails?

medium📝 component behavior Q13 of 15
Spring Boot - Exception Handling
Given this Spring Boot controller method snippet, what will be the HTTP response status if validation fails?
@PostMapping("/users")
public ResponseEntity createUser(@Valid @RequestBody User user) {
    return ResponseEntity.ok("User created");
}
A400 Bad Request
B200 OK
C500 Internal Server Error
D404 Not Found
Step-by-Step Solution
Solution:
  1. Step 1: Understand validation failure behavior

    When validation fails on a @Valid annotated object, Spring Boot returns a 400 Bad Request by default.
  2. Step 2: Check the method response

    The method returns 200 OK only if validation passes; failure triggers automatic 400 response.
  3. Final Answer:

    400 Bad Request -> Option A
  4. Quick Check:

    Validation fail status = 400 Bad Request [OK]
Quick Trick: Validation failure returns 400 Bad Request by default [OK]
Common Mistakes:
  • Assuming 200 OK even if validation fails
  • Thinking validation failure causes 500 error
  • Confusing 404 Not Found with validation errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes