title: How to get form errors in Symfony as JSON-object with JMSSerializer
body: <p>I need to have a generic JSON-representation of errors for any form that I have.</p>
  
  <p>I have already read other solutions like in <a href="https://stackoverflow.com/questions/24556121/how-to-return-json-encoded-form-errors-in-symfony">how to return json encoded form errors in symfony</a>. But I don't want to create one more service for task that is already can be solved by other bundle that I connected to my project.</p>
  
  <p>I use <code>JMSSerializerBundle</code> in my project and I know that this bundle can handle Symfony form errors using <code>FormErrorHandler</code>. But now I can get only whole form serialization:</p>
  
  <pre><code>$errors = $form-&gt;getErrors();
  $serializer = $this-&gt;get('jms_serializer');
  $json = $serializer-&gt;serialize($errors, 'json');
  </code></pre>
  
  <p>This code will return me next JSON-object:</p>
  
  <pre><code>{
      "form": {
          "children": {
              "field1": [],
              "field2": [],
              "field_with_error": {
                  "errors": ["Error text"]
              },
              "collection": {
                  "child_form": [
                      {
                          "children": {
                              "field1": [],
                              "field2": []
                          }
                      }
                  ]
              }
          }
      },
      "errors": []
  }
  </code></pre>
  
  <p>But I need something like that (only fields with errors):</p>
  
  <pre><code>{
      "field_with_error": {
          "errors": ["Error text"]
      }
  }
  </code></pre>
  
  <p>How can I achieve that? I looked at FOSRestBundle that has already solved this problem. But I didn't find how they did it.</p>