javanullbean-validationnotnull

java/beans validation - collection/map does not contain nulls


There is the @NotNull annotation which validates that a certain object is not null.

There is the @NotEmpty annotation which validates that a certain collection/map/string/... is not empty.

Is there also an annotation which valides that a certain collection/map does not contain any nulls? I am unable to find it. It seems so basic, that I believe it must be in the JSR-303 spec.


Solution

  • There is no such built-in constraints. You can easily write your custom constraints, eg @NoNullElements, which does what you want. Refer to the Refer to the documentation http://docs.jboss.org/hibernate/stable/validator/reference/en-US/html_single/#validator-customconstraints to see how to write custom constraints.