I have a Spring controller that validates incoming requests with hibernate validator.
When the request is invalid, MethodArgumentNotValidException is thrown by the validator. Would it be possible to add additional class as an argument to handler method for the exception?
This is what i have:
@RequestMapping(value = "/...", method = RequestMethod.POST)
@ResponseBody
public Response handleCustomObject(@Valid @RequestBody CustomObject obj) {
//..
}
@ExceptionHandler(MethodArgumentNotValidException.class)
@ResponseBody
public Response handleInvalidRequest(MethodArgumentNotValidException e) {
return getMissingMandatoryParametersResponse(e);
}
}
And i would need something like example bellow, however this doesn't work:
@ExceptionHandler(MethodArgumentNotValidException.class)
@ResponseBody
public Response handleInvalidRequest(MethodArgumentNotValidException e, CustomObject obj) {
// do something with CustomObject
}