title: How to extract the field name and the error message from the MethodArgumentNotValidException class?
body: <p>I am using <code>javax.validation.Size</code> annotation to perform String size validation.</p>
  
  <pre><code>@Data
  public class EventRequestBean {
  
      @Size( max = 40 )
      private String title;
  
      @Size( max = 50 )
      private String topic;
  }
  </code></pre>
  
  <p>And I am using a global exception handler to throw the custom exception to the client-side.</p>
  
  <pre><code>@ExceptionHandler( { MethodArgumentNotValidException.class } )
      public final ResponseEntity handleException( Exception e, WebRequest request )
      {
          if( e instanceof MethodArgumentNotValidException )
          {
              MethodArgumentNotValidException exception = (MethodArgumentNotValidException) e;
              String parameterName = exception.getParameter().getParameterName();
              //            return buildError(new DataException(GeneralConstants.EXCEPTION, "Invalid content length: field +"e))
  
              return null;
          }
  
          return null;
      }
  </code></pre>
  
  <p>In my custom exception <code>DataException</code>, the second argument is the error message. I want to set the field name and the valid size constraint as the message.</p>
  
  <p>I am trying to get the field name from the exception thrown, but instead of giving me the name <code>title</code>, it is giving me the parameter name <code>eventRequestBean</code> I am using in the controller from where this exception is thrown.</p>
  
  <pre><code>@PostMapping( "/event" )
      public ResponseEntity createEvent( @Valid @RequestBody EventRequestBean eventRequestBean )
      {
          try
          {
              log.info(GeneralConstants.LOGGER_CONSTANT,
                      " Entered create event controller, path:rest/events/event - POST");
              userCommons.throwExceptionForOtherThanAdminUser(getLoggedInUser());
              return buildResponse(eventService.addEvent(eventRequestBean, getLoggedInUser()));
          }
          catch( DataException e )
          {
              return buildError(e);
          }
      }
  </code></pre>
  
  <p>How can I get the field name and the set valid size so that I can create my own custom exception?</p>