[hibernate-dev] [Validator] Applying constraints to property objects

Hardy Ferentschik hardy at hibernate.org
Wed Sep 4 09:30:03 EDT 2013


On 3 Jan 2013, at 4:10 PM, Emmanuel Bernard <emmanuel at hibernate.org> wrote:

> Something like c makes sense.
> It similar to the notion of converter in JPA.
> 
> But why not the following style of interfaces
> 
>    interface Convert<From,To> {
>        To convert(From);
>    }


Going back to Emmanuel mentioning @Convert.  I am wondering whether using explicit annotations would not be more appropriate than an SPI?
It would of course be more verbose, but maybe the "converter" annotation could be applied on class level as well. The concern for me is really the
ambiguity 

 @Size(min=3, max=10)
  UIInput<String> name;

introduces. What if @Null or @NotNull is used. Does it apply to the String or the UIInput instance. It is not apparent anymore from the annotations what
is targeted. We already started introducing ambiguous cases in Bean Validation with method validation (cross parameter constraints, exclusion from getters
from validated methods), I am not sure we should continue on this path. 

Does the gain we achieve via the proposed SPI outweigh introducing even more border cases?

--Hardy


More information about the hibernate-dev mailing list