<div dir="ltr">All,<div><br></div><div>I just noticed that it&#39;s currently not possible to specify *no* validator type for cross-parameter constraints:</div><div><br></div><div style>@CrossParameterConstraint(validatedBy=...)</div>
<div style>MyCrossParamConstraint{ ... }</div><div style><br></div><div style>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&#39;s also not possible to specify ConstraintValidator.class as dummy value (doesn&#39;t compile). </div>
<div style><br></div><div style>Note that the problem doesn&#39;t exist with @Constraint where validatedBy() expects an array of class objects, allowing empty arrays. The following solutions come to my mind:</div><div style>
<br></div><div style>#1 Get rid of @CrossParameterConstraint, use @Validates on validator implementations, as discussed as alternative before<br></div><div style><br></div><div style>#2 Offer a dummy NoOpValidator in the API, obviously rather inelegant</div>
<div style><br></div><div style>#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</div><div style><br></div><div style>On a related note, if sticking to @CrossParameterConstraint, we may consider to narrow the type of supported validators:</div>
<div style><span class=""><br></span></div><div style><span class="">    public</span><span class=""> </span><span class="">@interface</span><span class=""> </span>CrossParameterConstraint<span class=""> {</span></div><div style>
        Class&lt;? <span class="">extends </span>ConstraintValidator&lt;?, Object[]&gt;&gt; validatedBy();</div><div style>    }</div><div style><br></div><div style>I.e., only validators for Object[] would be allowed (currently that&#39;s demanded by the JavaDocs only).</div>
<div style><br></div><div style>Any thoughts?</div><div style><br></div><div style>--Gunnar</div><div style><br></div></div>