Java Code Examples for org.springframework.validation.ObjectError#getObjectName()
The following examples show how to use
org.springframework.validation.ObjectError#getObjectName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GlobalControllerAdvice.java From springdoc-openapi with Apache License 2.0 | 6 votes |
@ExceptionHandler(MethodArgumentNotValidException.class) @ResponseStatus(code = HttpStatus.BAD_REQUEST) public ResponseEntity<ErrorMessage> handleMethodArgumentNotValid(MethodArgumentNotValidException ex ) { List<FieldError> fieldErrors = ex.getBindingResult().getFieldErrors(); List<ObjectError> globalErrors = ex.getBindingResult().getGlobalErrors(); List<String> errors = new ArrayList<>(fieldErrors.size() + globalErrors.size()); String error; for (FieldError fieldError : fieldErrors) { error = fieldError.getField() + ", " + fieldError.getDefaultMessage(); errors.add(error); } for (ObjectError objectError : globalErrors) { error = objectError.getObjectName() + ", " + objectError.getDefaultMessage(); errors.add(error); } ErrorMessage errorMessage = new ErrorMessage(errors); //Object result=ex.getBindingResult();//instead of above can allso pass the more detailed bindingResult return new ResponseEntity(errorMessage, HttpStatus.BAD_REQUEST); }
Example 2
Source File: GlobalControllerAdvice.java From springdoc-openapi with Apache License 2.0 | 6 votes |
@ExceptionHandler(MethodArgumentNotValidException.class) @ResponseStatus(code = HttpStatus.BAD_REQUEST) public ResponseEntity<ErrorMessage> handleMethodArgumentNotValid(MethodArgumentNotValidException ex ) { List<FieldError> fieldErrors = ex.getBindingResult().getFieldErrors(); List<ObjectError> globalErrors = ex.getBindingResult().getGlobalErrors(); List<String> errors = new ArrayList<>(fieldErrors.size() + globalErrors.size()); String error; for (FieldError fieldError : fieldErrors) { error = fieldError.getField() + ", " + fieldError.getDefaultMessage(); errors.add(error); } for (ObjectError objectError : globalErrors) { error = objectError.getObjectName() + ", " + objectError.getDefaultMessage(); errors.add(error); } ErrorMessage errorMessage = new ErrorMessage(errors); //Object result=ex.getBindingResult();//instead of above can allso pass the more detailed bindingResult return new ResponseEntity(errorMessage, HttpStatus.BAD_REQUEST); }
Example 3
Source File: GlobalControllerAdvice.java From springdoc-openapi with Apache License 2.0 | 6 votes |
@ExceptionHandler(MethodArgumentNotValidException.class) @ResponseStatus(code = HttpStatus.BAD_REQUEST) public ResponseEntity<ErrorMessage> handleMethodArgumentNotValid(MethodArgumentNotValidException ex ) { List<FieldError> fieldErrors = ex.getBindingResult().getFieldErrors(); List<ObjectError> globalErrors = ex.getBindingResult().getGlobalErrors(); List<String> errors = new ArrayList<>(fieldErrors.size() + globalErrors.size()); String error; for (FieldError fieldError : fieldErrors) { error = fieldError.getField() + ", " + fieldError.getDefaultMessage(); errors.add(error); } for (ObjectError objectError : globalErrors) { error = objectError.getObjectName() + ", " + objectError.getDefaultMessage(); errors.add(error); } ErrorMessage errorMessage = new ErrorMessage(errors); //Object result=ex.getBindingResult();//instead of above can allso pass the more detailed bindingResult return new ResponseEntity(errorMessage, HttpStatus.BAD_REQUEST); }
Example 4
Source File: ErrorAdvice.java From Microservices-with-Spring-Cloud with MIT License | 5 votes |
public ErrorMessage(ObjectError objectError) { message = objectError.getDefaultMessage(); code = objectError.getCode(); objectName = objectError.getObjectName(); if (objectError instanceof FieldError) { field = ((FieldError) objectError).getField(); } }
Example 5
Source File: ErrorAdvice.java From Microservices-with-Spring-Cloud with MIT License | 5 votes |
public ErrorMessage(ObjectError objectError) { message = objectError.getDefaultMessage(); code = objectError.getCode(); objectName = objectError.getObjectName(); if (objectError instanceof FieldError) { field = ((FieldError) objectError).getField(); } }
Example 6
Source File: ValidationResult.java From alf.io with GNU General Public License v3.0 | 4 votes |
public static ErrorDescriptor fromObjectError(ObjectError objectError) { return new ErrorDescriptor("", objectError.getObjectName(), objectError.getCode(), objectError.getArguments()); }