1

検証に使用できる制約はありList<Integer>ますか?そのため、どの値にも null が含まれない可能性がありますか?

更新しました

ここで提供されている回答に基づいてコードを変更しました: Hibernate Validation of Collections of Primitives

これは私が試したことです:

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

私のテストケースは、以下のテストコードで違反を検出しません:

@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());
}

ここで何か見逃しましたか?

4

0 に答える 0