title: API Platform - onPreSerialize with MediaObject URI Resolver in normalization group
body: <p>I have a MediaObject exposed as a subresource within a normalization context group "modules": </p>
  
  <pre><code>/**
   * @ApiResource(
   *     attributes={"access_control"="is_granted('ROLE_ADMIN')"},
   *     collectionOperations={
   *          "get",
   *          "post",
   *          "allData"={
   *              "method"="GET",
   *              "path"="/appdata",
   *              "normalization_context"={"groups"={"modules"}},
   *              "access_control"="is_granted('IS_AUTHENTICATED_ANONYMOUSLY')"
   *          }
   *     }
   * )
   * @ORM\Entity(repositoryClass="App\Repository\LearningModuleRepository")
   * @UniqueEntity("identifier")
   *
   */
  class LearningModule
  </code></pre>
  
  <pre><code>/**
   * @ORM\Entity(
   *     repositoryClass="App\Repository\MediaObjectRepository"
   * )
   * @ApiResource(
   *     iri="http://schema.org/MediaObject",
   *     normalizationContext={
   *         "groups"={"media_object_read"},
   *     },
   *     attributes={"access_control"="is_granted('ROLE_ADMIN')"},
   *     collectionOperations={
   *         "post"={
   *             "controller"=CreateMediaObject::class,
   *             "deserialize"=false,
   *             "validation_groups"={"Default", "media_object_create"},
   *             "swagger_context"={
   *                 "consumes"={
   *                     "multipart/form-data",
   *                 },
   *                 "parameters"={
   *                     {
   *                         "in"="formData",
   *                         "name"="file",
   *                         "type"="file",
   *                         "description"="The file to upload",
   *                     },
   *                 },
   *             },
   *         },
   *         "get",
   *     },
   *     itemOperations={
   *         "get",
   *         "delete"
   *     },
   * )
   * @Vich\Uploadable
   */
  class MediaObject
  
  
      /**
       * @var string|null
       *
       * @ApiProperty(iri="http://schema.org/contentUrl")
       * @Groups({"media_object_read", "modules"})
       */
      public $contentUrl;
  
      /**
       * @var string|null
       * @Groups({"modules"})
       * @ORM\Column(nullable=true)
       */
      public $filePath;
  </code></pre>
  
  <p>When exposed through the normalization group I only get filePath but not contentUrl. Im assuming the propblem has to do with the the ContentUrlSubscriber as outlined in the <a href="https://api-platform.com/docs/core/file-upload/#handling-file-upload" rel="nofollow noreferrer">official docs</a>: </p>
  
  <pre><code>    public static function getSubscribedEvents(): array
      {
          return [
              KernelEvents::VIEW =&gt; ['onPreSerialize', EventPriorities::PRE_SERIALIZE],
          ];
      }
  
      public function onPreSerialize(GetResponseForControllerResultEvent $event): void
      {
          $controllerResult = $event-&gt;getControllerResult();
          $request = $event-&gt;getRequest();
  
          if ($controllerResult instanceof Response || !$request-&gt;attributes-&gt;getBoolean('_api_respond', true)) {
              return;
          }
  
          if (!($attributes = RequestAttributesExtractor::extractAttributes($request)) || !\is_a($attributes['resource_class'], MediaObject::class, true)) {
              return;
          }
  
          $mediaObjects = $controllerResult;
  
          if (!is_iterable($mediaObjects)) {
              $mediaObjects = [$mediaObjects];
          }
  
          foreach ($mediaObjects as $mediaObject) {
              if (!$mediaObject instanceof MediaObject) {
                  continue;
              }
  
              $mediaObject-&gt;contentUrl = $this-&gt;storage-&gt;resolveUri($mediaObject, 'file');
          }
      }
  </code></pre>
  
  <p>Does anybody have a clue how to handle the preSerialization in this case? </p>
  
  <p>Thank You </p>