Thed
Thed

Reputation: 23

How can I validate indexed properties of JavaBean with Hibernate validator?

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?

Upvotes: 0

Views: 252

Answers (0)

Related Questions