Bird
0
0

Which annotation should be applied to a Spring Boot controller method parameter to enable automatic validation of a JSON request body?

easy📝 Conceptual Q2 of 15
Spring Boot - Exception Handling
Which annotation should be applied to a Spring Boot controller method parameter to enable automatic validation of a JSON request body?
A@Autowired
B@Valid
C@RequestParam
D@ResponseBody
Step-by-Step Solution
Solution:
  1. Step 1: Identify validation trigger

    @Valid is the standard annotation to trigger validation on method parameters.
  2. Step 2: Confirm usage with request body

    When combined with @RequestBody, @Valid ensures the incoming JSON is validated against constraints.
  3. Final Answer:

    @Valid -> Option B
  4. Quick Check:

    @Valid triggers validation on request body parameters [OK]
Quick Trick: Use @Valid to activate validation on request bodies [OK]
Common Mistakes:
  • Using @Autowired which is for dependency injection
  • Confusing @RequestParam which binds query parameters
  • Mistaking @ResponseBody which controls response serialization

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes