title: Modifying object output of a restful response using FOSRestBundle
body: <p>I'm having trouble achieving something that should be simple using FOSRestBundle.</p>
  
  <p>If I return an object, it works as intended. The JSON response will look something like </p>
  
  <pre><code>{ 
    id: ..., 
    property: ... 
  }
  </code></pre>
  
  <p>What I'd like to do is return, on all requests and status codes, a envelope for the response, something like </p>
  
  <pre><code>{
    meta: {
      code: 200,
      message: 'OK',
    }
    data: {
      id: ...,
      property: ...
    }
  }
  </code></pre>
  
  <p>This way, clients can write simple code to detect errors, where responses would look something like:</p>
  
  <pre><code>{
    meta: {
      code: 400,
      message: 'Your request failed because...',
    }
    data: {}
  }
  </code></pre>
  
  <p>I want to return this from multiple controllers, and return it only on JSON or XML requests. My first thought was to use a ResponseListener, check the format of the request, and modify the response if need be. Or, maybe, just set up a class something like 
  \Model\APIRequestFormatter, and from my controller, instead of doing a <code>return $entity;</code> do <code>return APIRequestFormatter-&gt;Format($entity);</code></p>
  
  <p>Both of these approaches seem flawed to me, does anyone have any tips?</p>