I am trying to use Spring validation to validate my model populated by Jackson converter.
So I have a java class,
class MyClass(){
private String myString;
}
This class is populated by Jackson and I have the instance in my Java code.
Have also defined a validator class like,
class MyValidator implements Validator {
public boolean supports(Class<?> clazz) {
return MyClass.class.equals(clazz);
}
public void validate(Object object, Errors errors) {
//Validation logic here
}
}
Now what I wanted to do was to send the object to the validator and get the errors object, examine and proceed further. But, for calling
validate(Object object,Errors errors)
I need an errors instance which I dont have. I cant use BindingResult or Errors. Please advise on how to proceed further.
You can do this manually in code with a DataBinder:
Although if you’ve got a @ModelAttribute defined in a @Controller in spring-mvc, something like this should work (placed inside the relevant @Controller):