| Hi Rene de Waele, thanks for providing that example; I think I understand what you have in mind, I'm still having doubts though whether that'd be the best thing to do. Specifically, your example would be better addressed by using the @Valid annotation like so:
class Foo {
@NotNull @Valid Bar bar;
}
class Bar {
Integer value;
@AssertTrue
boolean hasValidValue() {
return value.equals(42);
}
}
IIUC, this would result in the behavior you're after, in particular the NPE would be avoided, as the @AssertTrue constraint on Bar would only be validated if Foo#bar is not null. Or is this just addressing a specific sub-set of the cases you have in mind? |