Interface Constraint

All Superinterfaces:
Serializable
All Known Implementing Classes:
AbstractConstraint, DateIntervalConstraint, EnumConstraint, LengthConstraint, NotNullConstraint, NumericIntervalConstraint, ObjectResolverConstraint, PatternConstraint, TypeConstraint

public interface Constraint extends Serializable
A constraint object defines a constraint on a custom type. Method getDescription() allows anyone to dynamically redefine this constraint in another language (for example in javascript to make client-side validation).
Since:
7.1
  • Field Details

  • Method Details

    • validate

      boolean validate(Object object)
      Validates the given object against this constraint.

      If some object is null. Constraint should return true while validating unless the constraint deals with nullable state.

      Parameters:
      object - the object to validate
      Returns:
      true if the object was successfully validated, false otherwise
    • getErrorMessage

      String getErrorMessage(Object invalidValue, Locale locale)
      Provides an error message to display when some invalid value does not match existing entity.
      Parameters:
      invalidValue - The invalid value that don't match any entity.
      locale - The language in which the message should be generated.
      Returns:
      A message in the specified language or
      Since:
      7.1
    • getMessageKey

      String getMessageKey()
      Provides the message key.
      Returns:
      The message key
      Since:
      11.1
    • getDescription

      Constraint.Description getDescription()
      Provides a description of a constraint. For example, a constraint which control String format could return name=PatternMatchingConstraint | parameters= "pattern":"[0-9]+"
      Returns:
      The constraint description.
      Since:
      7.1