[bv-dev] Value extraction open issue #2: per constraint ConstraintsApplyTo?

Guillaume Smet guillaume.smet at gmail.com
Fri Jan 13 05:50:15 EST 2017


Hi,

This is the first of a series of threads about the open questions regarding
value extraction [1]. We hope having a separate thread per question will
help having a more structured and easy to follow discussion.

Summary of the issue
================

ConstraintsApplyTo only allows one behavior per annotated element. Should
it be per constraint? E.g. for @NotNull @Email StringProperty email it may
be desirable to apply @NotNull to the wrapper but @Email to the wrapped
value. That’s not possible currently.

Summary of the discussions going on
============================

Matt proposed something like:
@ConstraintsApplyTo(target=WRAPPED_VALUE, constraintTypes=Size.class)
@Size(3)
List<String> nicknames;

As noted by Emmanuel, it does not solve the issue when you want 2 @Size
constraints, one for the List and the other for the enclosed String.

Emmanuel proposed to use groups to solve this issue:
"
But it makes me think that we sorta addresssed a similar class of problem
with groups.
I haven’t explored at all but could we something similar by subverting
groups. Let’s define two special groups: OnContainer OnWrappedValue

@Min(value3, groups=OnWrappedValue.class)
List<String> nicknames;
"

[1] http://beanvalidation.org/latest-draft/spec/#_open_questions
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/beanvalidation-dev/attachments/20170113/06193761/attachment.html 


More information about the beanvalidation-dev mailing list