Question

I created a custom validator for method parameters.

@Target({ METHOD, CONSTRUCTOR, ANNOTATION_TYPE })
@Retention(RUNTIME)
@Constraint(validatedBy = {OpsaTimeRangeValidator.class})
public @interface OpsaTimeRangeConstraint
{
    String message() default "Failed to validate to and from ranges";

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

    Class<? extends Payload>[] payload() default {};

    //the index parameter in the method parameters for the from time
    int indexOfFromParameterInMethod();
    //the index parameter in the method parameters for the to time
    int indexOfToParameterInMethod();
}

@SupportedValidationTarget(ValidationTarget.PARAMETERS)
public class OpsaTimeRangeValidator implements ConstraintValidator<OpsaTimeRangeConstraint, Object[]

I have a rest service that is using resteasy, I am putting my annotation the rest method but the validation isn't called before the method is called.

What can be the problem ?

No correct solution

OTHER TIPS

You may need to enable Validation: Bean Validation 1.0.

Add following annotation to the class to enable validation on complete class, or add it to a method for method validation.

@ValidateRequest

This answer is more more precise (also for newer version)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top