All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.quarkus.hibernate.validator.runtime.ValidationSupport Maven / Gradle / Ivy

Go to download

Validate object properties (field, getter) and method parameters for your beans (REST, CDI, Jakarta Persistence)

There is a newer version: 3.17.5
Show newest version
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