@Pattern annotation on List of Strings

annotations, bean-validation, java, regex

Solution

See Container element constraints. With Bean Validation 2.0 you should be able to add your constraints to type arguments. In your case, you'll have:

@NotNull
private List<@Pattern(regexp="pattern-goes-here") String> myListOfStrings;

Problem

I am using javax.validation.constraints.Pattern. The pojo i'm adding the pattern also contains a List object. How can I add the @Pattern annotation so it would check the elements? ``` @NotNull private List<String> myListOfStrings; ``` Thanks

Original source