Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

Bean Validation / Collection Validators

Build Status Coverage Status Code quality Maven Central

Neither Bean Validation 1.1 (JSR 303/349) nor Hibernate Validator, the reference (and the only one…) implementation of it, provide simple way to validate a collection of basic types like String, Integer, Date… (i.e. validate each element of the collection).

This library allows you to easily create a “pseudo constraint” (typically named as @EachX) for any validation constraint to annotate a collection of simple types, without writing an extra validator or unnecessary wrapper classes for every collection. EachX constraint is supported for all standard Bean Validation constraints and Hibernate specific constraints. For example:

@EachSize(min = 5, max = 255)
Collection<String> values;

List<Date> dates;

Set<String> emails;

How to create a custom constraint

Every @EachX pseudo constraint uses the same validator, CommonEachValidator. To create an @EachAwesome for your own @Awesome constraint, just copy & paste the annotation class (i.e. all the attributes and boilerplate meta annotations), replace @Constraint annotation with @Constraint(validatedBy = CommonEachValidator.class) and add the annotation @EachConstraint(validateAs = Awesome.class). That’s all!

// common boilerplate
// this is important!
@EachConstraint(validateAs = Awesome.class)
@Constraint(validatedBy = CommonEachValidator.class)
public @interface EachAwesome {

    // copy&paste all attributes from Awesome annotation here
    String message() default "";
    Class<?>[] groups() default {};
    Class<? extends Payload>[] payload() default {};
    String someAttribute();

The old way

The previous versions (before 2.1.0) used a different approach to write @EachX annotations (see here). It is still supported for custom constraints, but all the built-in annotations has been already updated to the new style.

If you’re upgrading from an older version of Collection Validators, then you must update all built-in annotations to the new style. For example:

@EachSize(@Size(min = 5, max = 255)) -> @EachSize(min = 5, max = 255)

You should also update custom annotations. The old style is still supported, but may be deprecated in the future.


Released versions are available in The Central Repository. Just add this artifact to your project:


However if you want to use the last snapshot version, you have to add the JFrog OSS repository:

    <name>JFrog OSS repository for snapshots</name>


Hibernate Validator 4.3.1.Final and newer is supported, but 5.× is recommended.

Please note that on older versions some Hibernate specific constraints doesn’t exist, so their @EachX annotations will not work (e.g. @EachEAN, @EachMod10Check, …). It’s described in JavaDoc.

Version detection

In order to support multiple versions of Hibernate Validator at a time, we attempt to determine what version is being used at runtime using the package metadata for the HibernateValidator class. This can sometimes fail, particularly if your project creates an “uber JAR.” If the version cannot be detected, then it fallbacks to ≥ 5.1.0.


This project is licensed under MIT license.


The easiest way to validate collections of basic types using Bean Validation.





Sponsor this project



No packages published