java - Collection validation from single validator -


lets have class:

class foo{   @somecustomstringvalidator   string bar; } 

and have

class foo{    list<string> bars; } 

is there way use somehow @somecustomstringvalidator applied on bars collection ?

if using java 8, use latest hibernate validator 5.2 version. there is possible do:

class foo{   @valid   list<@somecustomstringvalidator string> bars; } 

otherwise use class wrapping approach mentioned in answer.

last not least, write custom constraintvalidator<somecustomstringvalidator, collection> , try sharing core validation logic between validator , `constraintvalidator have.


Comments