title: How to get error text in controller from BindingResult
body: <p>I have an controller that returns JSON.  It takes a form, which validates itself via spring annotations.  I can get FieldError list from BindingResult, but they don't contain the text that a JSP would display in the  tag. How can I get the error text to send back in JSON?</p>
  
  <pre><code>@RequestMapping(method = RequestMethod.POST)
  public
  @ResponseBody
  JSONResponse submit(@Valid AnswerForm answerForm, BindingResult result, Model model, HttpServletRequest request, HttpServletResponse response) {
  
      if (result.hasErrors()) {
          response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
          JSONResponse r = new JSONResponse();
          r.setStatus(JSONResponseStatus.ERROR);
          //HOW DO I GET ERROR MESSAGES OUT OF BindingResult??? 
      } else {
          JSONResponse r = new JSONResponse();
          r.setStatus(JSONResponseStatus.OK);
          return r;
      }
  
  }
  </code></pre>
  
  <p>JSONREsponse class is just a POJO</p>
  
  <pre><code>public class JSONResponse implements Serializable {
      private JSONResponseStatus status;
      private String error;
      private Map&lt;String,String&gt; errors;
      private Map&lt;String,Object&gt; data;
  
  ...getters and setters...
  }
  </code></pre>
  
  <p>Calling BindingResult.getAllErrors() returns an array of FieldError objects, but it doesn't have the actual errors.  </p>