<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jan 12, 2017 at 9:15 AM, Emmanuel Bernard <span dir="ltr"><<a href="mailto:emmanuel@hibernate.org" target="_blank">emmanuel@hibernate.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hey, thanks for the feedback Matt<br>
<span class="gmail-"><br>
> On 11 Jan 2017, at 17:45, Matt Benson <<a href="mailto:mbenson@apache.org">mbenson@apache.org</a>> wrote:<br>
><br>
> I generally like this; I think the proposal is in quite good shape. My reactions to the open questions:<br>
><br>
> 1. Should nested containers be supported?<br>
> Given the Optional<List<@Email String>> example, it's probably a good idea (certainly it adds some complexity, but anything worth doing is worth doing right, as the saying goes).<br>
><br>
> 2. Should @ConstraintsApplyTo be usable per-constraint?<br>
> Doing such seems like it could be a bit clumsy, but it might be okay if @ConstraintsApplyTo were repeatable and included Class<? extends Annotation>[] constraintTypes() default {} element which, if non-empty, could differentiate which constraints applied to the wrapper vs. the extracted value.<br>
<br>
</span>Do you mean?<br>
<br>
@ConstraintAppliesTo(target=<wbr>WRAPPED_VALUE, constraintTypes=Min.class)<br>
@Min(3)<br>
List<String> nicknames;<br>
<br>
This approach cannot cover a case were the Min constraint it used one for the container and one for the wrapped value.<br></blockquote><div><br></div><div>That is what I was postulating, yes. Min might not be the best example. NotNull might be a better example of a constraint that one would want to apply both to the wrapper and the extracted value.</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
But it makes me think that we sorta addresssed a similar class of problem with groups.<br>
I haven’t explored at all but could we something similar by subverting groups. Let’s define two special groups: OnContainer OnWrappedValue<br>
<br>
@Min(value3, groups=OnWrappedValue.class)<br>
List<String> nicknames;<br>
// note that these examples are simplifications and should really be written List<@Min String> nicknames;<br>
// but pretend we have a subclass of List<String> with no way to put a TYPE_USE constraint<br>
<br></blockquote><div><br></div><div>The idea is kind of cute (for lack of a better word), but doesn't this complicate or prevent "normal" use of validation groups?</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
This proposal would not address the case of multiple nestsed containers List<List<String>><br>
<span class="gmail-"><br></span></blockquote><div><br></div><div>I agree that specifying WRAPPED_VALUE per-property is ambiguous for List<List<String>>. Maybe that is an argument against allowing #8. What if the rule were that @ConstraintsApplyTo(WRAPPED_VALUE) is valid on TypeExtractor class definitions, while @ConstraintsApplyTo(ANNOTATED_ELEMENT) is valid elsewhere, serving only to override the behavior specified by the extractor? Then you could have @Size(min=5) @ConstraintsApplyTo(ANNOTATED_ELEMENT) List<@Size(min=3) @ConstraintsApplyTo(ANNOTATED_ELEMENT) List<String>> . This still doesn't solve #2, but I think the problems are orthogonal.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-">
><br>
> 3. Should @ConstraintsApplyTo also be used for tagging extractors triggering "auto-extraction"?<br>
> I'm not sure I understand this question. Is this referring to classpath scanning, or "inline" specification of extractors? In either case a separate annotation might be warranted, particularly if the annotation is expanded for other reasons (see #2).<br>
<br>
</span>No it’s to define that a given extractor prefers to target the wrapped value vs targeting the container<br>
<br>
@ConstraintsApplyTo(WRAPPED_<wbr>VALUE)<br>
class OptionalExtractor … {}<br>
<br>
@Min(2) Optional<String> foo;<br>
// equivalent to @Min @ConstraintsApplyTo(WRAPPED_<wbr>VALUE) Optional<String> foo;<br>
<br>
This behavior is hardcoded for Optional in the spec for info.<br>
<span class="gmail-"><br></span></blockquote><div>Are you saying that question #3 is just asking for validation of this idea as outlined in the current draft? Then my answer is yes.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-">
><br>
> 4. Should a path node be added for type argument constraints of Optional and similar types?<br>
> I don't personally feel this is necessary, but I wouldn't oppose it if others strongly desired it.<br>
><br>
> 5. Should value extractors be discoverable via ServiceLoader?<br>
> I would personally really like to see this be possible. WRT being able to override these, it seems simple enough that value extractors registered programmatically or in validation.xml could preempt any discovered via ServiceLoader.<br>
><br>
> 6. What to return from PropertyDescriptor#<wbr>getElementClass() if field type does not match method RT?<br>
> The Javadoc of PropertyDescriptor references "Java Beans." Java Bean properties are defined by method signatures rather than fields, so it seems an easy decision to choose the method RT over the field signature.<br>
><br>
> 7. Should the presence of type argument constraints alone trigger nested validation?<br>
> I can appreciate the sense of the consistency argument to requiring @Valid, but in practice it seems reasonable to me that @Valid be implied. It probably would be much simpler to require @Valid from an implementation perspective, however.<br>
<br>
</span>I personally am a bit reluctant. Do we really think that this is the default behavior people will want? Because you cannot negate a @Valid today so that’s a definitive decision. It seems to be that many containers are not beans per se and don’t want their properties to be validated, just the extacted stuff,.<br>
<br></blockquote><div>Are you saying that type argument constraints will be validated using extraction, but that only validation of the Map object *itself* would depend on @Valid to trigger validation of Map values per BV 1.x? So if Address had validation metadata, you could have:<br></div><div><br></div><div>Map<AddressType, @NotNull Address></div><div><br></div><div>And BV would validate that the values were non-null, but would not invoke Address validation without @Valid on the Map (BV 1.x) or on the Address type parameter? That makes sense to me. You could then combine:</div><div><br></div><div>Map<AddressType, @NotNull @Valid Address></div><div><br></div><div>Matt </div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
[more reading later]<br>
<div class="gmail-HOEnZb"><div class="gmail-h5"><br>
<br>
______________________________<wbr>_________________<br>
beanvalidation-dev mailing list<br>
<a href="mailto:beanvalidation-dev@lists.jboss.org">beanvalidation-dev@lists.<wbr>jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/beanvalidation-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/<wbr>mailman/listinfo/<wbr>beanvalidation-dev</a></div></div></blockquote></div><br></div></div>