<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 7 Nov 2016, at 23:42, Hendrik Ebbers <<a href="mailto:hendrik.ebbers@me.com" class="">hendrik.ebbers@me.com</a>> wrote:</div><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class="">In addition I think that simply adding a constraints annotation to the generic type is wrong. All examples that we have mentioned are just perfect examples in that the generic type defines the content. Let’s say we have a class like this:<br class=""><br class=""><font face="Courier New" class="">public abstract class ConvertableInteger<V> {<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>private int value;<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>public void setValue(int value) { this.value = value; }<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>public int getValue() { return value; }<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>public abstract V getConvertedValue();<br class="">}</font><br class=""><br class="">If you want to validate an instance of this class you normally want to validate the integer and not the converted value:<br class=""><br class=""><font face="Courier New" class="">private ConvertableInteger<@Min(2_000_000) Date> myValue;</font><br class=""><br class="">Such an expression looks like if you want to validate a Date object. In this case the better solution would be something like this:<br class=""><br class=""><font face="Courier New" class="">@Min(2_000_000)<br class="">private ConvertableInteger<Date> myValue;</font></div></div></blockquote><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class="">And now we end in 2 different ways how we annotation value wrappers:<br class=""><br class=""><font face="Courier New" class="">private CachableValue<@NotEmpty String> myCachedValue;<br class=""><br class="">@Min(2_000_000)<br class="">private ConvertableInteger<Date> myIntegerValue;</font><br class=""></div></div></blockquote><div><br class=""></div></div><div class="">First off, your specific example does not work as is as the class is abstract. You would need an explicit subclass (e.g. DateConvertableInteger extends ConvertableInteger<Date>). And in that situation, The more natural BV approach would be to do this:</div><div class=""><br class=""></div><div class="">public class DateConvertableInteger extend ConvertableInteger<Date> {</div><div class=""><br class=""></div><div class=""> @Min(@2_000_000)</div><div class=""> public int getValue() { return value; }</div><div class=""><br class=""></div><div class=""> @NotEmpty</div><div class=""> public Date getConvertedValue();</div><div class="">}</div><div class=""><br class=""></div><div class="">class SomeClass {</div><div class=""> @Valid</div><div class=""> private StringConvertableInteger myValue;</div><div class="">}</div><div class=""><br class=""></div><div class="">== overriding constraint declarations</div><div class=""><br class=""></div><div class="">Now if you want a way to override the constraints of an embedded (@Valid) object (graph), then I think that is a different subject that we can try and address. JPA for example has the notion of @AttributeOverride. It is more complicated in the case of Bean Validation as we would need to override actual annotations. Not sure how to express that for now. Do we think that it is a valid and important requirement?</div><div class=""><br class=""></div><div class="">To clarify, here is what is required</div><div class=""><br class=""></div><div class="">public class Embeddable {</div><div class=""> @NotEmpty String foo;</div><div class="">}</div><div class=""><br class=""></div><div class="">public class Entity {</div><div class=""> @Valid @Override(path=“foo”, constraints=@Min(3)) // note that this is not valid Java syntax</div><div class=""> Embeddable embeddable;</div><div class="">}</div><div class=""><br class=""></div><div class="">== Constraint on non parameterized containers</div><div class=""><br class=""></div><div class="">That raises another question, the proposal allows to to three things:</div><div class=""><br class=""></div><div class="">- apply constraints on a type use generic declaration(*): Collection<@NotEmpty String> foo;</div><div class="">- apply constraints on specialized generic parameters (*): @Pattern(…) StringProperty prop; //where StringProperty extends Property<String></div><div class="">- apply constraints on container with no generic: @Min(3) IntegerContainer prop; // where class IntegerContainer{ Integer value; } i.e. no generic</div><div class=""><br class=""></div><div class="">(*) I don’t know the actual proper names so sorry if I butchered notions</div><div class=""><br class=""></div><div class="">I am liking option 3 less and less and as far as I can remember, it does not rely on an explicitly identified use case. Who is wanting to support that usage, vs restrict the container feature to parameterized containers?</div><div class=""><br class=""></div>I’m not sure I was all that clear, so please ask any question if you have any doubt.<div class=""><br class=""></div><div class="">Emmanuel</div></body></html>