Complete the code to add a validation annotation that ensures the 'name' field is not empty.
public class UserRequest { @[1] private String name; // getters and setters }
The @NotEmpty annotation ensures the field is not null and not empty.
Complete the code to validate that the 'age' field is at least 18.
public class UserRequest { @Min([1]) private int age; // getters and setters }
The @Min(18) annotation ensures the age is at least 18.
Fix the error in the validation annotation to ensure the 'email' field is a valid email address.
public class UserRequest { @[1] private String email; // getters and setters }
The @Email annotation validates that the string is a valid email format.
Fill both blanks to validate that the 'password' field is not null and has a minimum length of 8.
public class UserRequest { @[1] @[2](min = 8) private String password; // getters and setters }
@NotNull ensures the password is not null, and @Size(min = 8) ensures it has at least 8 characters.
Fill all three blanks to create a map of field names to their validation error messages using Spring's BindingResult.
Map<String, String> errors = new HashMap<>(); for (FieldError error : bindingResult.getFieldErrors()) { errors.put(error.get[1](), error.get[2]()); } return ResponseEntity.badRequest().body(errors.get([3]));
error.getField() gets the field name, error.getDefaultMessage() gets the error message, and the map is accessed with the field name "email".