+

Search Tips   |   Advanced Search

Bean validation built-in constraints

Use this information to look up information about Bean Validation API built-in constraints.

The Bean Validation API is supported by constraints that are primarily expressed through annotations. The constraints are added to a class, field, or method of an EJB component. The annotated element value is checked by the constraint.

Constraints can be built in or user defined. Several built-in annotations are available in the javax.validation.constraints package. They are used to define regular constraint definitions and for composing constraints.

The following table is a list of constraints and usage.

Constraint Usage
@Null That the configuration property decorated with this annotation must have a null value. This constraint accepts any type.
@NotNull That the configuration property decorated with this annotation must not have a null value. That is, the property is required. This constraint accepts any type.
@AssertTrue That the configuration property decorated with this annotation must be true. Supported value types are boolean and Boolean. Null elements are considered valid.
@AssertFalse That the configuration property decorated with this annotation must be false. Supported value types are boolean and Boolean. Null elements are considered valid.
@Min That the configuration property decorated with this annotation must have a value greater than or equal to the specified minimum. Supported value types are BigDecimal, BigInteger, byte, short, int, long and their respective wrappers. Null elements are considered valid.
@Max That the configuration property decorated with this annotation must have a value less than or equal to the specified maximum. Supported value types are BigDecimal, BigInteger, byte, short, int, long and their respective wrappers. Null elements are considered valid.
@DecimalMin That the configuration property decorated with this annotation must have a value higher or equal to the specified minimum. Supported value types are BigDecimal, BigInteger, String, byte, short, int, long and their respective wrappers. Null elements are considered valid.
@DecimalMax That the configuration property decorated with this annotation must have a value lower or equal to the specified maximum. Supported value types are BigDecimal, BigInteger, String, byte, short, int, long and their respective wrappers. Null elements are considered valid.
@Size That the configuration property decorated with this annotation must have a value between the specified boundaries (included). Supported value types are String (string length is evaluated), Collection (collection size is evaluated), Map (map size is evaluated), Array (array length is evaluated). Null elements are considered valid.
@Digits That the configuration property decorated with this annotation must have a value within accepted range. Supported value types are BigDecimal, BigInteger, String, byte, short, int, long and their respective wrappers. Null elements are considered valid.
@Past That the configuration property decorated with this annotation must have a date in the past. Now is defined as the current time according to the virtual machine. The calendar is used if the compared type is of type Calendar and the calendar is based on the current timezone and the current locale. Supported value types are java.util.Date, java.util.Calendar. Null elements are considered valid.
@Future That the configuration property decorated with this annotation must have a date in the future. Now is defined as the current time according to the virtual machine. The calendar is used if the compared type is of type Calendar and the calendar is based on the current timezone and the current locale. Supported value types are java.util.Date, java.util.Calendar. Null elements are considered valid.
@Pattern That the configuration property decorated with this annotation must match the following regular expression. The regular expression follows the Java regular expression conventions java.util.regex.Pattern. Supported type value is String. Null elements are considered valid.


Related:

  • Bean validation in RAR modules
  • Bean Validation
  • Bean validation troubleshooting tips
  • Troubleshoot bean validation in RAR modules