0

I have an indexed property such as

private int[] indexedProperty;

According to spec I should provide indexed accessors. Would constraints declared on these accessors be valid? Should I also provide array accessors and declare @Valid constraint on it?

For ex, would whole array be validated in this case:

@Max(10)
public int getIndexedProperty(int i) {
    return indexedProperty[i];
}

Or may be also this is needed:

@Valid
public int[] getIndexedProperty() {
    return indexedProperty;
}

is there also some best practices or rule of thumb for validating index for indexed accessors? Should I either check it in accessors with ArrayIndexOutOfBoundsException or intercept accessors and validate parameter with validator?

Thed
  • 23
  • 7
  • There is a similar situation here:http://stackoverflow.com/questions/32069126/validate-elements-of-a-string-array-with-java-bean-validation/32075122#32075122 – Franck Oct 05 '15 at 14:56
  • Oh, thanks a lot! I've sought by keywords like "validating indexed property" but not "validating an array property". It seems like an inner wrapping class would be better for me. – Thed Oct 05 '15 at 15:11

0 Answers0