java - Spring REST validation on custom annotation -


i'm trying add validation logic on rest beans using annotations. example, point annotation used on multiple rest resource objects / dto's.

i hoping solution this:

public class entity {      @notnull // jsr-303     private string name;      @phone // custom phonenumber has exist in database     private string phonenumber; }  @component public class phonenumbervalidator implements validator { // spring validator      @autowired     private phonerepository repository;      public boolean supports(class<?> clazz) {        return true;     }      public void validate(object target, errors errors) {         phone annotation = // find fields annotations iterating on target.getclass().getfields().getannotation         object fieldvalue = // how do this? can annotation, wish call repository checking if field value exists.     } } 

did try jsr 303 bean validator implementations hibernate validator e.g. available here http://www.codejava.net/frameworks/spring/spring-mvc-form-validation-example-with-bean-validation-api


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -