Custom validation with javax.validation

Tags: , ,

I’m trying to make a custom java validation annotation and returns me

Request processing failed; nested exception is javax.validation.ConstraintDeclarationException: HV000144: Cross parameter constraint is illegally placed on field ‘private java.util.List’.”

the code is really naive

@Target({ FIELD, METHOD})
@Constraint(validatedBy = ConstraintValidation.class)
public @interface CustomConstraint {

    String message() default "this is the default message";

    Class<?>[] groups() default {};

    Class<? extends Payload>[] payload() default {};
public class ConstraintValidationimplements ConstraintValidator<CustomConstraint , List<ElementOfTheList>> {

    public boolean isValid(List<ElementOfTheList> value, ConstraintValidatorContext context) {
        System.out.println("only a sysout to test");
        return true;

And in the rest object model

  @NotNull(message ="not null message")
  @NotEmpty(message = "not empty message")
  private List<ElementOfTheList> list = null;






since you want to validate and element (here is List list) and not the parameters of a method or a constructor

Source: stackoverflow