title: How to return Repository Objects as Json on Symfony2
body: <p>I'm trying to return the users like this, but of course it doesn't work, I need the data as JSon since im working with BackboneJs</p>
  
  <pre><code>/**
  * @Route("/mytest",name="ajax_user_path")
  */
  public function ajaxAction()
  {
      $em = $this-&gt;get('doctrine')-&gt;getManager();
      $users = $this-&gt;get('doctrine')-&gt;getRepository('GabrielUserBundle:Fosuser')-&gt;findAll();
  
      $response = array("users"=&gt;$users);            
      return new Response(json_encode($response));
  }
  </code></pre>