Search in sources :

Example 1 with NotBlank

use of jakarta.validation.constraints.NotBlank in project minijax by minijax.

the class MinijaxConstraintDescriptor method build.

@SuppressWarnings("unchecked")
public static <T extends Annotation> MinijaxConstraintDescriptor<T> build(final AnnotatedType annotatedType, final T annotation) {
    final Constraint constraint = annotation.annotationType().getAnnotation(Constraint.class);
    if (constraint == null) {
        return null;
    }
    final Class<?> valueClass = ReflectionUtils.getRawType(annotatedType);
    final Class<?> annotationClass = annotation.annotationType();
    if (constraint.validatedBy().length > 0) {
        return buildDeclaredValidator(annotation, constraint.validatedBy()[0]);
    } else if (annotationClass == AssertFalse.class) {
        return (MinijaxConstraintDescriptor<T>) buildAssertFalseValidator((AssertFalse) annotation, valueClass);
    } else if (annotationClass == AssertTrue.class) {
        return (MinijaxConstraintDescriptor<T>) buildAssertTrueValidator((AssertTrue) annotation, valueClass);
    } else if (annotationClass == Max.class) {
        return (MinijaxConstraintDescriptor<T>) buildMaxValidator((Max) annotation, valueClass);
    } else if (annotationClass == Min.class) {
        return (MinijaxConstraintDescriptor<T>) buildMinValidator((Min) annotation, valueClass);
    } else if (annotationClass == NotBlank.class) {
        return (MinijaxConstraintDescriptor<T>) buildNotBlankValidator((NotBlank) annotation, valueClass);
    } else if (annotationClass == NotEmpty.class) {
        return (MinijaxConstraintDescriptor<T>) buildNotEmptyValidator((NotEmpty) annotation, valueClass);
    } else if (annotationClass == NotNull.class) {
        return (MinijaxConstraintDescriptor<T>) buildNotNullValidator((NotNull) annotation);
    } else if (annotationClass == Pattern.class) {
        return (MinijaxConstraintDescriptor<T>) buildPatternValidator((Pattern) annotation, valueClass);
    } else if (annotationClass == Size.class) {
        return (MinijaxConstraintDescriptor<T>) buildSizeValidator((Size) annotation, valueClass);
    } else {
        throw new ValidationException("Unrecognized constraint annotation: " + annotation);
    }
}
Also used : Pattern(jakarta.validation.constraints.Pattern) ValidationException(jakarta.validation.ValidationException) Constraint(jakarta.validation.Constraint) Max(jakarta.validation.constraints.Max) Size(jakarta.validation.constraints.Size) AssertTrue(jakarta.validation.constraints.AssertTrue) NotNull(jakarta.validation.constraints.NotNull) Min(jakarta.validation.constraints.Min) NotBlank(jakarta.validation.constraints.NotBlank) AssertFalse(jakarta.validation.constraints.AssertFalse) NotEmpty(jakarta.validation.constraints.NotEmpty)

Aggregations

Constraint (jakarta.validation.Constraint)1 ValidationException (jakarta.validation.ValidationException)1 AssertFalse (jakarta.validation.constraints.AssertFalse)1 AssertTrue (jakarta.validation.constraints.AssertTrue)1 Max (jakarta.validation.constraints.Max)1 Min (jakarta.validation.constraints.Min)1 NotBlank (jakarta.validation.constraints.NotBlank)1 NotEmpty (jakarta.validation.constraints.NotEmpty)1 NotNull (jakarta.validation.constraints.NotNull)1 Pattern (jakarta.validation.constraints.Pattern)1 Size (jakarta.validation.constraints.Size)1