[bv-dev] Specifying no validator for cross-param constraint

Gunnar Morling gunnar at hibernate.org
Fri Feb 8 08:56:51 EST 2013


All,

I just noticed that it's currently not possible to specify *no* validator
type for cross-parameter constraints:

@CrossParameterConstraint(validatedBy=...)
MyCrossParamConstraint{ ... }

Not specifying a validator might be relevant for people who want to hide
their validator implementations and e.g. configure them via XML. Null is
not allowed as annotation member value, and it's also not possible to
specify ConstraintValidator.class as dummy value (doesn't compile).

Note that the problem doesn't exist with @Constraint where validatedBy()
expects an array of class objects, allowing empty arrays. The following
solutions come to my mind:

#1 Get rid of @CrossParameterConstraint, use @Validates on validator
implementations, as discussed as alternative before

#2 Offer a dummy NoOpValidator in the API, obviously rather inelegant

#3 Ignore the problem, maybe the use case is really uncommon? If required,
recommend people to use their own dummy validator and override it via XML

On a related note, if sticking to @CrossParameterConstraint, we may
consider to narrow the type of supported validators:

    public @interface CrossParameterConstraint {
        Class<? extends ConstraintValidator<?, Object[]>> validatedBy();
    }

I.e., only validators for Object[] would be allowed (currently that's
demanded by the JavaDocs only).

Any thoughts?

--Gunnar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/beanvalidation-dev/attachments/20130208/6e46a476/attachment.html 


More information about the beanvalidation-dev mailing list