Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define a validation group interface.
Spring Boot
public interface [1] {} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Defining methods inside the validation group interface
Using class instead of interface
✗ Incorrect
Validation groups in Spring Boot are defined as empty interfaces. Here, 'CreateUserGroup' is a common name for a group used during user creation validation.
2fill in blank
mediumComplete the annotation to apply a validation group to a field.
Spring Boot
@NotNull(groups = [1].class) private String username;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting '.class' after the group name
Using the wrong group interface name
✗ Incorrect
The 'groups' attribute specifies which validation group the constraint belongs to. 'CreateUserGroup.class' applies the constraint only when that group is validated.
3fill in blank
hardFix the error in the validation call to validate only the 'CreateUserGroup'.
Spring Boot
Set<ConstraintViolation<User>> violations = validator.validate(user, [1]); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the default group instead of the specific group
Forgetting '.class' suffix
✗ Incorrect
To validate only constraints in the 'CreateUserGroup', pass 'CreateUserGroup.class' to the validate method.
4fill in blank
hardFill both blanks to define two validation groups and apply them to fields.
Spring Boot
public interface [1] {} public interface [2] {} @NotNull(groups = CreateGroup.class) private String name; @NotNull(groups = UpdateGroup.class) private String id;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same group name for both interfaces
Not matching group names in annotations
✗ Incorrect
Two groups 'CreateGroup' and 'UpdateGroup' are defined and used to apply validation constraints conditionally.
5fill in blank
hardFill all three blanks to create a map of field names to validation groups and check if a field belongs to a group.
Spring Boot
Map<String, Class<?>> fieldGroups = Map.of( "username", [1].class, "email", [2].class, "password", [3].class ); boolean isUsernameInCreate = fieldGroups.get("username") == CreateGroup.class;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using string literals instead of class references
Mixing up group names
✗ Incorrect
The map associates fields with their validation groups. The check compares the group of 'username' to 'CreateGroup.class'.