I am using validation-api-2.0.1.Final and hibernate-validator-6.0.13.Final. I would like to do validation for the below case,
I have created a custom validation to validate List<Map<String,Object>>
BookInfo.java
@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Constraint(
validatedBy = {BookInfoValidator.class}
)
public @interface BookInfo {
String message() default "Should not be empty";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
}
BookInfoValidator.java
public class BookInfoValidator implements ConstraintValidator<ValidateUserInfo, List<Map<String, Object>>> {
private final ContentRepositoryClient contentRepository;
public ValidateUserInfoValidator(ContentRepositoryClient contentRepository) {
this.contentRepository = contentRepository;
}
@Override
public void initialize(ValidateUserInfo constraintAnnotation) {
}
@Override
public boolean isValid(List<Map<String,Object>> map, ConstraintValidatorContext constraintValidatorContext) {
//In the list of Map the key will be "text,email,date etc etc" based on the key i would like to
//validate with the proper validation constraints
//ex) for Email invoke javax.validation.constraints.Email.class from validation-api
//I am not sure how to manually invoke the validation annotations.
return false;
}
}
BookInfoView.java
class BookInfoView {
@BookInfo
private List<Map<String, Object>> bookInfos;
}
In the list of Map the key will be "text, email, date etc". Based on the key I would like to validate with the proper validation constraints
exception for Email invoke javax.validation.constraints.Email.class from validation-api. I am not sure how to manually invoke the validation annotations.
Any hint or help will be much appreciated.