QuizzesBean Validation with @Valid — Concept Check
intermediate
spring-boot

Bean Validation with @Valid — Concept Check

Questions on Bean Validation with @Valid. JSR-303/380 constraints (@NotNull, @Size, @Email) on request DTOs are enforced automatically when @Valid is placed on the method parameter.

7 minutes 7 questions Pass at 70%
Time Limit
7 minutes - timer starts when you begin
Change Answers Freely
Revisit and change any answer before submitting
Full Review After Submit
Correct answers and explanations shown for every question
Auto-submit on timeout
Quiz submits automatically when time runs out

Questions in this quiz

7 questions on Bean Validation with @Valid — Concept Check. Work through them here, then start the quiz to answer them and see your score.

  1. 1.A developer uses @Valid on a controller method parameter. What happens if validation fails?

    • AA 500 Internal Server Error is returned
    • BThe request is silently ignored
    • CA MethodArgumentNotValidException is thrown
    • DThe method executes with default values
  2. 2.In a Spring Boot application, a DTO field is annotated with @NotNull and @Email. What happens if the field is null?

    • AThe method proceeds without error
    • BThe email format is checked
    • CA default email is assigned
    • DA validation error occurs
  3. 3.A DTO field is annotated with @Size(min=5, max=10). What happens if the input is 4 characters long?

    • AThe method executes with a warning
    • BThe input is truncated
    • CA validation error occurs
    • DThe input is padded
  4. 4.A developer uses @Validated(OnCreate.class) on a method. What does this achieve?

    • AValidates only nested objects
    • BApplies specific validation rules for creation
    • CApplies default validation rules
    • DIgnores all validation rules
  5. 5.A DTO field is annotated with @Pattern(regexp="^[0-9]{5}$"). What input will pass validation?

    • A1234
    • Babcde
    • C12345
    • D123456
  6. 6.A developer believes @Valid on a nested object is unnecessary. Why is this incorrect?

    • ANested objects are validated by default
    • B@Valid is only for top-level objects
    • CNested objects require @Valid for cascaded validation
    • D@Valid is deprecated for nested objects
  7. 7.What is the role of @ControllerAdvice in handling validation errors?

    • AExecutes business logic
    • BIgnores validation errors
    • CMaps exceptions to structured responses
    • DLogs validation errors