Recall & Review
beginner
What is the purpose of the @Size annotation in Spring Boot?
The @Size annotation is used to set minimum and maximum length constraints on a string, collection, map, or array to ensure the data meets length requirements before processing.
Click to reveal answer
beginner
How do you specify the minimum and maximum length using @Size?
You use the attributes min and max inside @Size, for example: @Size(min = 3, max = 10) means the value must be at least 3 and at most 10 characters long.
Click to reveal answer
intermediate
Can @Size be used on collections like List or arrays?
Yes, @Size works on collections, arrays, and maps to restrict the number of elements they contain, not just strings.
Click to reveal answer
intermediate
What happens if a value violates the @Size constraints in Spring Boot?
Spring Boot's validation framework will detect the violation and typically return an error response indicating the size constraint was not met, preventing further processing.
Click to reveal answer
beginner
Write a simple example of @Size used on a username field in a Spring Boot model.
Example: <br>
@Size(min = 5, max = 15, message = "Username must be between 5 and 15 characters")<br>private String username;Click to reveal answer
What does @Size(min = 2, max = 8) enforce on a string?
✗ Incorrect
@Size with min and max sets inclusive length boundaries for the string.
Can @Size be applied to a List in Spring Boot?
✗ Incorrect
@Size works on collections like List to restrict their size.
What attribute of @Size sets the maximum allowed length?
✗ Incorrect
The max attribute defines the maximum length allowed.
If a field annotated with @Size(min=3) has a value of length 2, what happens?
✗ Incorrect
Values shorter than min cause validation failure.
Which package provides the @Size annotation in Spring Boot?
✗ Incorrect
@Size is part of the javax.validation.constraints package.
Explain how @Size helps in validating user input in Spring Boot applications.
Think about how length limits protect data quality.
You got /4 concepts.
Describe a scenario where using @Size on a List would be useful.
Consider forms where users select multiple options.
You got /4 concepts.