Class ConstraintViolationMetadata
java.lang.Object
fr.paris.lutece.portal.util.mvc.binding.validate.ConstraintViolationMetadata
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 Summary
ConstructorsConstructorDescriptionConstraintViolationMetadata(jakarta.validation.ConstraintViolation<?> violation, Annotation[] annotations) Constructs a ConstraintViolationMetadata instance with the given violation and annotations. -
Method Summary
Modifier and TypeMethodDescriptiongetAnnotation(Class<Annotation> type) Return an Optional containing the first annotation of the specified type, if presentRetrieves the parameter name associated with the violation.booleanhasAnnotation(Class<? extends Annotation> type) Checks if the metadata contains an annotation of the specified type.
-
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 violationannotations- the annotations associated with the violation
-
-
Method Details
-
getAnnotation
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
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
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
-