title: Symfony Serializer: Deserializing Json to Entity
body: <p>I am trying to use Symfony's Serializer to deserialize a Json to my entity &quot;DossierDTO&quot;.</p>
  <pre><code>class DossierDTO 
  {
      #[Groups(['test'])]
      public string $idActeurCreateur; 
     
      #[Groups(['test'])]
      public string $idDossierVise;   
   
      #[Groups(['test'])]
      public string $idProjet;
  
      public ArrayCollection $personnes;
      public ArrayCollection $terrains;
      .
      .
      .
      more fields
  
  </code></pre>
  <p>I would like to deserialize only the fields tagged with the #[Groups(['test'])] annotations.</p>
  <p>Here is my call to fetch the json object and my attempt to deserialize it:</p>
  <pre><code>/**
  * Make a request to API
  * @param string $method: request method (POST, GET...)
  * @param string $suffix: URI suffix (/example)
  * @param array $body: request body
  * @throws Exception 
  * @return ResponseInterface
  */
  public function myRequest(string $method, string $suffix, ?array $body): ResponseInterface
      {   
          $jsonContent = is_null($body) ? json_encode(new stdClass) : $this-&gt;serializer-&gt;serialize($body, 'json');
          try {
              $response = $this-&gt;client-&gt;request($method, $this-&gt;infos[&quot;uri&quot;] . $suffix, [
                  'headers' =&gt; $this-&gt;infos[&quot;headers&quot;],
                  'body' =&gt; $jsonContent
                  ]);
              } catch (Exception $e) {
                  $this-&gt;logger-&gt;error($e-&gt;getMessage());
              }
          $dossier = $this-&gt;serializer-&gt;deserialize($response-&gt;getContent(), DossierDTO::class, 'json', [&quot;groups&quot; =&gt; &quot;test&quot;]);
          dd($dossier, $response-&gt;getContent());
  }
  
  </code></pre>
  <p>And this is what my dump shows:</p>
  <p><a href="https://i.stack.imgur.com/gVSZ2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gVSZ2.png" alt="enter image description here" /></a></p>
  <p>So basically, I don't get the fields that I would like to, even when I remove the &quot;#[Groups(['test'])]&quot; the result is the same.</p>
  <p>It always shows me the two ArrayCollection fields (empty) and only these...
  I'm working with Symfony 5.2.9</p>