0
0
Spring Bootframework~10 mins

Validation groups in Spring Boot - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a validation group interface.

Spring Boot
public interface [1] {}
Drag options to blanks, or click blank then click option'
ACreateUserGroup
BUserValidator
CValidationGroup
DCheckGroup
Attempts:
3 left
💡 Hint
Common Mistakes
Defining methods inside the validation group interface
Using class instead of interface
2fill in blank
medium

Complete 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'
ACreateUserGroup
BUserGroup
CValidationGroup
DDefaultGroup
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting '.class' after the group name
Using the wrong group interface name
3fill in blank
hard

Fix 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'
ADefault.class
BCreateUserGroup.class
CUserGroup.class
DValidationGroup.class
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the default group instead of the specific group
Forgetting '.class' suffix
4fill in blank
hard

Fill 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'
ACreateGroup
BUpdateGroup
CUserGroup
DValidationGroup
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same group name for both interfaces
Not matching group names in annotations
5fill in blank
hard

Fill 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'
ACreateGroup
BUpdateGroup
CResetGroup
DDefaultGroup
Attempts:
3 left
💡 Hint
Common Mistakes
Using string literals instead of class references
Mixing up group names