diff --git a/src/main/java/jakarta/validation/metadata/ConstraintDescriptor.java b/src/main/java/jakarta/validation/metadata/ConstraintDescriptor.java index fd53ab15..82bf0ba0 100644 --- a/src/main/java/jakarta/validation/metadata/ConstraintDescriptor.java +++ b/src/main/java/jakarta/validation/metadata/ConstraintDescriptor.java @@ -92,6 +92,24 @@ public interface ConstraintDescriptor { */ Map getAttributes(); + /** + * Returns the value of the annotation attribute. + *

+ * Serves as a shortcut to {@code (V) getAttributes().get(attrName);}. + *

+ * If this constraint is used as part of a composed constraint, attribute + * values are reflecting the overridden attribute of the composing constraint. + * + * @param name the name of the constraint attribute to retrieve + * @param type the class of the attribute to be returned + * @return the value of a requested attribute, or {@code null} if such attribute is not defined. + * @param the type of the attribute to be returned + * @throws ClassCastException if the actual attribute value cannot be cast to the requested type. + * @see #getAttributes() + * @since 4.0 + */ + V getAttribute(String name, Class type); + /** * Return a set of composing {@link ConstraintDescriptor}s where each * descriptor describes a composing constraint. {@code ConstraintDescriptor}