com.bld.commons.connection.utils.ValidatorUtils Maven / Gradle / Ivy
/**
* @author Francesco Baldi
* @mail [email protected]
* @class com.bld.commons.connection.utils.ValidatorUtils.java
*/
package com.bld.commons.connection.utils;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Component;
import jakarta.validation.ConstraintViolation;
import jakarta.validation.Validation;
import jakarta.validation.Validator;
import jakarta.validation.ValidatorFactory;
/**
* The Class ValidatorUtils.
*/
@Component
public class ValidatorUtils {
/** The Constant logger. */
private final static Log logger = LogFactory.getLog(ValidatorUtils.class);
/** The Constant VALIDATOR. */
private final static Validator VALIDATOR=getValidator();
/**
* Gets the validator.
*
* @return the validator
*/
private static Validator getValidator() {
ValidatorFactory valdiatorFactory = Validation.buildDefaultValidatorFactory();
return valdiatorFactory.getValidator();
}
/**
* Check validatr build class.
*
* @param obj the obj
* @throws Exception the exception
*/
public static void checkValidatrBuildClass(Object obj) throws Exception {
Set> failedValidations = VALIDATOR.validate(obj);
if (!failedValidations.isEmpty()) {
for (ConstraintViolation
© 2015 - 2025 Weber Informatics LLC | Privacy Policy