title: Symfony Serialize doctrine entity
body: <p>I have a simple entity class:</p>
  
  <pre><code>&lt;?php
  namespace AppBundle\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  use Doctrine\Common\Collections\ArrayCollection;
  
  
  /**
   * @ORM\Entity(repositoryClass="CompanyUserRepository")
   * @ORM\Table(name="company_users")
   */
  class CompanyUser
  {
  /**
   * @ORM\Column(type="integer")
   * @ORM\Id
   * @ORM\GeneratedValue(strategy="AUTO")
   */
  private $id;
  
  /**
   * @ORM\Column(type="string", length=100)
   */
  private $firstName;
  
  /**
   * @ORM\Column(type="string", length=100)
   */
  private $lastName ;
  
  /**
   * @ORM\OneToMany(targetEntity="Score", mappedBy="user")
   */
  private $scores;
  /**
   * Constructor
   */
  public function __construct()
  {
      $this-&gt;scores = new ArrayCollection();
  }
  
  /**
   * Get id
   *
   * @return integer
   */
  public function getId()
  {
      return $this-&gt;id;
  }
  
  /**
   * Set firstName
   *
   * @param string $firstName
   *
   * @return CompanyUser
   */
  public function setFirstName($firstName)
  {
      $this-&gt;firstName = $firstName;
  
      return $this;
  }
  
  /**
   * Get firstName
   *
   * @return string
   */
  public function getFirstName()
  {
      return $this-&gt;firstName;
  }
  
  /**
   * Set lastName
   *
   * @param string $lastName
   *
   * @return CompanyUser
   */
  public function setLastName($lastName)
  {
      $this-&gt;lastName = $lastName;
  
      return $this;
  }
  
  /**
   * Get lastName
   *
   * @return string
   */
  public function getLastName()
  {
      return $this-&gt;lastName;
  }
  
  /**
   * Add score
   *
   * @param \AppBundle\Entity\Score $score
   *
   * @return CompanyUser
   */
  public function addScore(\AppBundle\Entity\Score $score)
  {
      $this-&gt;scores[] = $score;
  
      return $this;
  }
  
  /**
   * Remove score
   *
   * @param \AppBundle\Entity\Score $score
   */
  public function removeScore(\AppBundle\Entity\Score $score)
  {
      $this-&gt;scores-&gt;removeElement($score);
  }
  
  /**
   * Get scores
   *
   * @return \Doctrine\Common\Collections\Collection
   */
  public function getScores()
  {
      return $this-&gt;scores;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>The problem comes when I try to get all users and serialize them in json:</p>
  
  <pre><code>/**
   * @Route("/api/getUsers", name="getUsers")
   */
  public function getUsers(Request $request){
      $users = $this-&gt;getDoctrine()
      -&gt;getRepository('AppBundle:CompanyUser')
      -&gt;findAll();
  
      $serializer = $this-&gt;get('serializer');
      $data = $serializer-&gt;serialize($users, 'json');
  
      return new Response($users);
  }
  </code></pre>
  
  <p>I get <em>A circular reference has been detected (configured limit: 1).</em>
  When I remove the getScores getter everything works fine. I need to get only the id, firstName and lastName. Is there a way to not serialize the other objects?</p>