Class ValidatorConstraintResolver

java.lang.Object
org.springframework.restdocs.constraints.ValidatorConstraintResolver
All Implemented Interfaces:
ConstraintResolver

public class ValidatorConstraintResolver extends Object implements ConstraintResolver
A ConstraintResolver that uses a Bean Validation Validator to resolve constraints. The name of the constraint is the fully-qualified class name of the constraint annotation. For example, a NotNull constraint will be named jakarta.validation.constraints.NotNull.
Author:
Andy Wilkinson
  • Constructor Details

    • ValidatorConstraintResolver

      public ValidatorConstraintResolver()
      Creates a new ValidatorConstraintResolver that will use a Validator in its default configuration to resolve constraints.
      See Also:
      • Validation.buildDefaultValidatorFactory()
      • ValidatorFactory.getValidator()
    • ValidatorConstraintResolver

      public ValidatorConstraintResolver(jakarta.validation.Validator validator)
      Creates a new ValidatorConstraintResolver that will use the given Validator to resolve constraints.
      Parameters:
      validator - the validator
  • Method Details

    • resolveForProperty

      public List<Constraint> resolveForProperty(String property, Class<?> clazz)
      Description copied from interface: ConstraintResolver
      Resolves and returns the constraints for the given property on the given clazz. If there are no constraints, an empty list is returned.
      Specified by:
      resolveForProperty in interface ConstraintResolver
      Parameters:
      property - the property
      clazz - the class
      Returns:
      the list of constraints, never null