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
Post a Comment