Challenge - 5 Problems
Size Constraint Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What happens when a string field annotated with @Size(min=5, max=10) receives a 3-character input?
Consider a Spring Boot entity with a field annotated as
@Size(min=5, max=10). What will be the validation result if the input string length is 3?Spring Boot
public class User { @Size(min=5, max=10) private String username; // getters and setters }
Attempts:
2 left
💡 Hint
Remember that @Size checks both minimum and maximum length constraints.
✗ Incorrect
The @Size annotation enforces that the string length must be between the specified min and max values inclusive. Since the input length is 3, which is less than the minimum 5, validation fails.
📝 Syntax
intermediate2:00remaining
Which @Size annotation usage is syntactically correct for a list field in Spring Boot?
You want to validate a list to have between 2 and 5 elements using @Size. Which option is correct?
Spring Boot
public class Group {
@Size(???)
private List<String> members;
}Attempts:
2 left
💡 Hint
Check the official @Size annotation parameters for min and max.
✗ Incorrect
The @Size annotation uses named parameters min and max to specify length constraints. The correct syntax is @Size(min=2, max=5).
🔧 Debug
advanced2:00remaining
Why does this @Size annotation not enforce the maximum length?
Given the code below, why does the validation allow strings longer than 10 characters?
Spring Boot
public class Product { @Size(min=3) private String code; // getters and setters }
Attempts:
2 left
💡 Hint
Check if both min and max are specified to enforce length limits.
✗ Incorrect
The @Size annotation enforces minimum and maximum length only if both min and max are set. If max is missing, there is no upper limit.
❓ state_output
advanced2:00remaining
What is the validation result for a null string annotated with @Size(min=1, max=5)?
If a string field is annotated with
@Size(min=1, max=5) and the input value is null, what happens during validation?Spring Boot
public class Item { @Size(min=1, max=5) private String label; // getters and setters }
Attempts:
2 left
💡 Hint
Think about how @Size treats null values by default.
✗ Incorrect
The @Size annotation does not consider null values invalid. Null is allowed unless combined with @NotNull.
🧠 Conceptual
expert2:00remaining
How does @Size behave differently on a String vs a Collection in Spring Boot validation?
Which statement correctly describes the difference in how @Size validates Strings and Collections?
Attempts:
2 left
💡 Hint
Think about what length means for strings and collections.
✗ Incorrect
@Size counts characters in Strings and counts elements in Collections to enforce min and max constraints.