Reputation: 788
I have this REST API method
@GetMapping
public ResponseEntity doSome(@Valid DataTypeRequest dataType){}
and ConstraintValidator
that validates DataTypeRequest
.
Now I should implement HandlerMethodArgumentResolver for DataTypeRequest, so my REST API method will look like:
@GetMapping
public ResponseEntity doSome(@Valid @DataTypeRequestAnnotation DataTypeRequest dataType){}
And after this changes HandlerMethodArgumentResolver
works but ConstraintValidator doesn't. So how can I validate my entity after HandlerMethodArgumentResolver.
Upvotes: 1
Views: 167
Reputation: 36
You can check parameter for @Valid
and invoke validate()
method.
if (parameter.hasParameterAnnotation(Valid.class){
binderFactory
.createBinder(webRequest, resolvedObject, "resolvedObjectLogicalName")
.validate ();
}
Upvotes: 1