io.quarkus.hibernate.validator.runtime.ValidationSupport Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of quarkus-hibernate-validator Show documentation
Show all versions of quarkus-hibernate-validator Show documentation
Validate object properties (field, getter) and method parameters for your beans (REST, CDI, Jakarta Persistence)
package io.quarkus.hibernate.validator.runtime;
import jakarta.validation.Validation;
import jakarta.validation.ValidatorFactory;
import org.hibernate.validator.HibernateValidatorFactory;
import io.quarkus.arc.Arc;
import io.quarkus.arc.ArcContainer;
import io.quarkus.arc.InstanceHandle;
public final class ValidationSupport {
private ValidationSupport() {
}
public static ValidatorFactory buildDefaultValidatorFactory() {
ArcContainer container = Arc.container();
if (container == null) {
return fallback();
}
InstanceHandle instance = container.instance(HibernateValidatorFactory.class);
if (!instance.isAvailable()) {
return fallback();
}
return new CloseAsNoopValidatorFactoryWrapper(instance.get());
}
// the point of having this is to support non-Quarkus tests that could be using Hibernate Validator
private static ValidatorFactory fallback() {
return Validation.byDefaultProvider().configure().buildValidatorFactory();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy