Class ConstraintViolationMetadata

java.lang.Object
fr.paris.lutece.portal.util.mvc.binding.validate.ConstraintViolationMetadata

public class ConstraintViolationMetadata extends Object
Metadata class that holds information about a constraint violation and its associated annotations. This class provides methods to retrieve specific annotations and parameter names from the violation.
  • Constructor Details

    • ConstraintViolationMetadata

      public ConstraintViolationMetadata(jakarta.validation.ConstraintViolation<?> violation, Annotation[] annotations)
      Constructs a ConstraintViolationMetadata instance with the given violation and annotations.
      Parameters:
      violation - the constraint violation
      annotations - the annotations associated with the violation
  • Method Details

    • getAnnotation

      public Optional<Annotation> getAnnotation(Class<Annotation> type)
      Return an Optional containing the first annotation of the specified type, if present
      Parameters:
      type - the type of annotation to retrieve
      Returns:
      an Optional containing the first annotation of the specified type, if present
    • hasAnnotation

      public boolean hasAnnotation(Class<? extends Annotation> type)
      Checks if the metadata contains an annotation of the specified type.
      Parameters:
      type - the type of annotation to check for
      Returns:
      true if the annotation is present, false otherwise
    • getParamName

      public Optional<String> getParamName()
      Retrieves the parameter name associated with the violation. It checks for specific annotations like RequestParam, RequestHeader, ModelAttribute, and CookieValue, and returns the appropriate value based on the annotation's value or the property path of the violation.
      Returns:
      an Optional containing the parameter name