package com.lij.himeeter.common.utils.bean;

import jakarta.validation.ConstraintViolation;
import jakarta.validation.ConstraintViolationException;
import jakarta.validation.Validator;

import java.util.Set;

/**
 * <pre>
 *
 * 文件名 :  BeanValidators
 * 创建时间 : 2024年12月31日 16:59
 *
 * 文件描述 : bean对象属性验证
 *
 * </pre>
 *
 * @author Nobita
 * @version 1.0.0
 */

public class BeanValidators {

    public static void validateWithException(Validator validator, Object object, Class<?>... groups)
            throws ConstraintViolationException {
        Set<ConstraintViolation<Object>> constraintViolations = validator.validate(object, groups);
        if (!constraintViolations.isEmpty()) {
            throw new ConstraintViolationException(constraintViolations);
        }
    }
}
