javaarraysvalidationoval

How to validate a array using oval validation framework?


I have a bean object and want to validate its fields using oval validation framework. e.g

public class Demo{

    @Range(min=1)
    private long id;

    @NotNull
    private long[] values;
}

As above, I have a field whose type is a array of long. I want to ensure that the array is not null and each element in it must be greater than zero. I don't know how to validate to ensure that its elements are greater than zero. Anyone can tell me ? Thanks.


Solution

  • You can use the appliesTo attribute:

    @NotNull(appliesTo = {ConstraintTarget.CONTAINER, ConstraintTarget.VALUES})
    private long[] values;