Custom validator is being called multiple times

Discussão em 'StackOverflow' iniciado por Stack, Janeiro 25, 2021.

  1. Stack

    Stack Membro Participativo

    I have created a custom bean validator annotation

    @Documented
    @Constraint(validatedBy = TestValidator.class)
    @Target({ElementType.PARAMETER})
    @Retention(RetentionPolicy.RUNTIME)

    public @interface ValidTest {
    String message() default "org.cdot.validations.ValidTest";

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


    And its corresponding validator class

    public class TestValidator implements ConstraintValidator<ValidTest, String> {

    @Override
    public void initialize(ValidTest annot) {
    }

    @Override
    public boolean isValid(String param, ConstraintValidatorContext ctx) {
    System.out.println("[isValid] param : " + param);
    return param != null && param.trim().length() > 0;
    }
    }


    In my Bean I have a test method

    @POST
    @Path("validtest")
    @Produces(MediaType.TEXT_PLAIN)
    public String testMethod(@ValidTest String param) {
    System.out.println("[testMethod] param : " + param);
    return "";
    }


    The issue is that when the EAR is deployed in Wildfly, and the API is called with parameter, isValid is being called three times. Whereas if the API is called with not parameter, the method is being called only once.

    Can someone please help me on this? Thanks

    Continue reading...

Compartilhe esta Página