title: How can I seralize to json with circular reference handler in Symfony?
body: <p>I want to serialize my database table into a json file:</p>
  
  <pre><code>$table = $this-&gt;em-&gt;getRepository($EntityName)-&gt;findAll();
  
  $classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
  
  $encoders = [new JsonEncoder()]; 
  $normalizers = [new DateTimeNormalizer(array('datetime_format' =&gt; 'd.m.Y')), new ObjectNormalizer($classMetadataFactory)];
  $serializer = new Serializer($normalizers, $encoders);
  
  $context = [
      'circular_reference_handler' =&gt; function ($object) {
          return $object-&gt;getId();
      },
      'circular_reference_limit' =&gt; 0,
  ];
  
  $data = $serializer-&gt;serialize($table, 'json', $context);
  </code></pre>
  
  <p>But I have some problems with the performance. My page loads really slow, for several seconds, and then I get a blank page. </p>