title: Symfony 4.2 Custom Circular Reference Handler Does not Apply
body: <p>The context is that I have been trying to set up a Custom Circular Reference Handler for my entities that will effect ALL entities. </p>
  
  <p>According to documentation ( <a href="https://symfony.com/doc/current/components/serializer.html#handling-circular-references" rel="nofollow noreferrer">https://symfony.com/doc/current/components/serializer.html#handling-circular-references</a> ), we are guided to set the <code>circular_reference_handler</code> value under the <code>serializer</code> service in the <code>config/packages/framework.yaml</code> file as such: </p>
  
  <pre><code>framework:
      validation:
          enabled: true
  
      messenger:
          enabled: true
  
      assets:
          enabled: true
  
      serializer:
          circular_reference_handler: App\Services\CircularReferenceHandler
          enable_annotations: true
  </code></pre>
  
  <p>My actual problem is that when the serializer attempts to load the circular reference handler my override doesn't seem to exist: 
  <a href="https://ibb.co/KGp92MS" rel="nofollow noreferrer">image showing key referenced</a>
  <a href="https://ibb.co/B4gdJhy" rel="nofollow noreferrer">image showing context empty</a></p>
  
  <p>Why isn't my override getting applied to the context at all?? </p>
  
  <p>I have attempted to:</p>
  
  <ul>
  <li>Reload cache</li>
  <li>Use a ContextBuilder class from my API Platform package</li>
  <li>Apply it in a Normalizer</li>
  </ul>
  
  <p>None of have worked</p>
  
  <p>I showed you my yaml, but here is the handler: </p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  
  namespace App\Services;
  
  class CircularReferenceHandler
  {
      /**
       * @param object $object
       * @return mixed
       */
      public function __invoke($object)
      {
          return $object-&gt;getId();
      }
  }
  </code></pre>
  
  <p>and here is the Context builder I attempted to use as an alternative: </p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  
  namespace App\Serializer;
  
  use ApiPlatform\Core\Serializer\SerializerContextBuilderInterface;
  use App\Services\CircularReferenceHandler;
  use Symfony\Component\HttpFoundation\Request;
  use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
  
  final class GlobalSerializerContextBuilder implements SerializerContextBuilderInterface
  {
      /**
       * Creates a serialization context from a Request.
       *
       * @param Request    $request
       * @param bool       $normalization
       * @param array|null $extractedAttributes
       *
       * @return array
       */
      public function createFromRequest(Request $request, bool $normalization, array $extractedAttributes = null): array
      {
          $resourceClass = $context['resource_class'] ?? null;
  
          $context[AbstractNormalizer::CIRCULAR_REFERENCE_HANDLER] = CircularReferenceHandler::class;
  
          return $context;
      }
  }
  </code></pre>
  
  <p>and here is where I registered that ( <a href="https://api-platform.com/docs/core/serialization/#changing-the-serialization-context-dynamically" rel="nofollow noreferrer">doc</a> ): </p>
  
  <pre><code>    App\Serializer\GlobalSerializerContextBuilder:
          decorates: 'api_platform.serializer.context_builder'
          arguments: ['@App\Serializer\GlobalSerializerContextBuilder.inner']
          autoconfigure: false
  </code></pre>
  
  <p><strong>I expected</strong> my custom circular_reference_handler to be applied when the <code>AbstractNormalizer-&gt;handleCircularReference()</code> method is used, <strong>but the actuality</strong> is the context received in this method does not include my additional key/value pair ( e.g. <code>['circular_reference_handler =&gt; App\Services\CircularReferenceHandler]</code></p>