@Size(min=5, max=10). What will be the validation result if the input string length is 3?public class User { @Size(min=5, max=10) private String username; // getters and setters }
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.
public class Group {
@Size(???)
private List<String> members;
}The @Size annotation uses named parameters min and max to specify length constraints. The correct syntax is @Size(min=2, max=5).
public class Product { @Size(min=3) private String code; // getters and setters }
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.
@Size(min=1, max=5) and the input value is null, what happens during validation?public class Item { @Size(min=1, max=5) private String label; // getters and setters }
The @Size annotation does not consider null values invalid. Null is allowed unless combined with @NotNull.
@Size counts characters in Strings and counts elements in Collections to enforce min and max constraints.
