Bean Validation — Concept Check
Questions on Bean Validation. Jakarta Bean Validation (@Valid, @NotBlank, @Size, @Email) validates request bodies before they reach your service. Custom validators handle business rules that built-in constraints can't express.
Questions in this quiz
7 questions on Bean Validation — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.A developer adds @Valid to a @RequestBody parameter in a Spring Boot application. What happens if the request body violates constraints?
- AA MethodArgumentNotValidException is thrown
- BThe request is ignored
- CThe application crashes
- DThe constraints are ignored
2.A user submits a form with an email that is already registered. The email field has @UniqueEmail. What is the expected behavior?
- AThe request fails with an email already registered error
- BThe email field is ignored
- CThe request succeeds without issue
- DThe email is automatically replaced with a unique one
3.What is the purpose of the @Valid annotation in a Spring Boot controller method?
- ATo log request details for debugging
- BTo convert the request body to XML
- CTo ensure the method only accepts JSON
- DTo trigger validation of the request body before method execution
4.An API returns a 400 error with validation details. What likely caused this response?
- AA timeout during request processing
- BA constraint violation in the request body
- CA server-side processing error
- DAn incorrect endpoint URL
5.Which built-in constraint would you use to ensure a field is not null and not empty?
- A@Pattern
- B@NotNull
- C@NotBlank
- D@Size
6.A developer implements a ConstraintValidator for a custom annotation. What is a common mistake they might make?
- AUsing @NotNull instead of @NotBlank
- BUsing @Size for number validation
- CNot handling null values properly
- DForgetting to annotate fields
7.What happens if a nested object in a DTO is annotated with @Valid but contains invalid fields?
- AThe request succeeds with warnings
- BOnly the nested object is ignored
- CThe invalid fields are set to default values
- DThe entire request is rejected with detailed errors