I would like to be able to validate the primitives inside a list and I was wondering if there's a standard way of doing it. For example validating the size of the Strings inside a list.
An example:
@Size(max = 64) // validates that a string is max 64 chars.
private String name;
@Size(max = 64) // validates that the list size is max 64 items.
private List<String> names;
// What I want:
@ValidateInsidePrimitives(
@Size(max = 64)
)
private List<String> names;
What I've seen people do is wrap the primitives into an object do do this:
@Valid
private List<NameObj> names;
OR making custom annotations that validate a list of strings:
@MyCustomListStringSizeAnnotation(max = 64)
private List<String> names;
OR using the java 8 new annotations placement like so:
private List<@Size(max = 64) String> names;
But I don't really like the first 2 approaches, and I CANNOT port my app to java 8.
It seems to me that the "@ValidateInsidePrimitives" I drafted above should work (after all the *.List annotations do take annotations) but I wasn't able to find something like that. Any ideas?