[bv-dev] Type use constraints for field *and* property

Gunnar Morling gunnar at hibernate.org
Fri Dec 2 10:20:29 EST 2016


Hi,

As you may have seen, Emmanuel started a survey on how people would like to
use type-level constraints in Bean Validation:
http://beanvalidation.org/news/2016/11/23/survey-constraints-and-parameterized-type/

While we are waiting for some more replies to that one, I started with a
PoC implementation of the value extractor idea in the reference
implementation in order to get a better feeling for it, it's limitations,
open questions etc.:
https://github.com/hibernate/hibernate-validator/pull/592

One thing we started to wonder is whether it should be allowed to put
type-level constraints to a field *and* the corresponding property getter
at the same time:

    private List<@NotBlank String> strings;

    public List<@Pattern(regexp="...") String> getStrings() { return
strings; }

My first inclination was to say that it should be supported (as you can put
regular constraints to a field and its getter). A challenge is how to
obtain the values for constraint validation. In the spirit of BV 1 we'd
have to iterate the values directly from the field for evaluating the
@NotBlank constraint and a second time through the getter for @Pattern
validation. That's a potential performance issue of course.

What do others think?

Thanks,

--Gunnar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/beanvalidation-dev/attachments/20161202/34efc413/attachment-0001.html 


More information about the beanvalidation-dev mailing list