ValidatorImpl:validateConstraintsForDefaultGroup
ValidatorFactoryImpl(constraintHelper)
constraintHelper中添加了各种默认的验证器
public ValidatorFactoryImpl(ConfigurationState configurationState) { this.messageInterpolator = configurationState.getMessageInterpolator(); this.traversableResolver = configurationState.getTraversableResolver(); this.parameterNameProvider = configurationState.getParameterNameProvider(); this.beanMetaDataManagerMap = Collections.synchronizedMap( new IdentityHashMap<ParameterNameProvider, BeanMetaDataManager>() ); this.constraintHelper = new ConstraintHelper(); this.typeResolutionHelper = new TypeResolutionHelper(); this.executableHelper = new ExecutableHelper( typeResolutionHelper );
Constraint这个注解是很重要的 groups等两个方法也是必须
@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER }) @Retention(RUNTIME) @Constraint(validatedBy = { JSONValidator.class }) public @interface BeJSON { String message() default "{must.be.json.format}"; public Class<?>[] groups() default {}; Class<? extends Payload>[] payload() default {}; }
继承ConstraintValidator
public class JSONValidator implements ConstraintValidator<BeJSON, CharSequence> {
错误
but does not contain a groups parameter