1

Is there such constraint that can be used for validating List<Integer> thus none of the values may contain null ?

UPDATED

I changed my code based on the answer provided here: Hibernate Validation of Collections of Primitives

This what I have tried:

@ValidCollection(elementType=Integer.class, constraints={NotNull.class})
private List<Integer> quantities;

My test case does not find any violations on below test code:

@Test
public void beanNotConstrained() {
    PurchaseForm pForm = new PurchaseForm();
    pForm.setQuantities(new ArrayList<Integer>());
    pForm.getQuantities().add(1);
    pForm.getQuantities().add(null);

    Validator validator = getValidator();

    Set<ConstraintViolation<PurchaseForm>> violations = validator.validate(pForm);
    for(ConstraintViolation<PurchaseForm> violation : violations) {
      logger.info(violation.getMessage());
    }
    Assert.assertEquals(1, violations.size());
}

Did I miss out anything here ?

Community
  • 1
  • 1
abiieez
  • 3,139
  • 14
  • 57
  • 110

0 Answers0