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

Hardy Ferentschik hardy at hibernate.org
Fri Feb 8 10:10:33 EST 2013


Hi,

Is this not where 'include-existing-validators="true"' in the XML config comes into play as well?
So it is still possible to configure via XML with the default constraint implementation in- or excluded.  
I don't see a need for a provided NoOpValidator provided by the API. If you don't want to provide a 
actual implementation you can create your own dummy. 

I still against option #1. So I guess I reasoned myself into #3

--Hardy




On 8 Jan 2013, at 2:56 PM, Gunnar Morling <gunnar at hibernate.org> wrote:

> 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
> 
> _______________________________________________
> beanvalidation-dev mailing list
> beanvalidation-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/beanvalidation-dev




More information about the beanvalidation-dev mailing list