Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.github.edgarespina.mwa.handler;
 import java.util.List;
 import java.util.Map;
public class BindHandlerExceptionResolver extends
Creates a new BindHandlerExceptionResolver.

exceptionClass The exception class. Required.
      final Class<? extends ExceptionexceptionClass) {


  protected Object convert(final Exception exception) {
    return convert(((BindExceptionexception).getBindingResult());

Use a custom format for org.springframework.validation.BindingResult.
  1. field: The field's name. Optional.
  2. rejectedValue: The rejected value. Optional.
  3. message: The error message.
  4. type: The error type.
  5. source: The root/contianer object.
  protected Object convert(final BindingResult bindingResult) {
    List<ObjectErrorbindingErrors = bindingResult.getAllErrors();
    List<Objecterrors = new ArrayList<Object>(bindingErrors.size());
    for (ObjectError objectError : bindingErrors) {
      String field = null;
      Object rejectedValue = null;
      if (objectError instanceof FieldError) {
        FieldError fieldError = (FieldErrorobjectError;
        field = fieldError.getField();
        rejectedValue = fieldError.getRejectedValue();
      Map<StringObjecterror = new HashMap<StringObject>();
      error.put("message", (StringUtils.trimToEmpty(field) + " " + objectError
      error.put("type", StringUtils.uncapitalize(objectError.getCode()));
    return errors;
New to GrepCode? Check out our FAQ X