title: Denormalize nested structure in objects with Symfony 2 serializer
body: <p>I'm working on a Symfony 2 project with version 2.8 and I'm using the build-in component Serializer -&gt; <a href="http://symfony.com/doc/current/components/serializer.html" rel="nofollow noreferrer">http://symfony.com/doc/current/components/serializer.html</a></p>
  <p>I have a JSON structure provided by a web service.
  After deserialization, I want to denormalize my content in objects. Here is my structure (model/make in a car application context).</p>
  <pre><code>[{
  &quot;0&quot;: {
      &quot;id&quot;: 0,
      &quot;code&quot;: 1,
      &quot;model&quot;: &quot;modelA&quot;,
      &quot;make&quot;: {
          &quot;id&quot;: 0,
          &quot;code&quot;: 1,
          &quot;name&quot;: &quot;makeA&quot;
      }
    }
  } , {
   &quot;1&quot;: {
      &quot;id&quot;: 1,
      &quot;code&quot;: 2,
      &quot;model&quot;: &quot;modelB&quot;,
      &quot;make&quot;: {
          &quot;id&quot;: 0,
          &quot;code&quot;: 1,
          &quot;name&quot;: &quot;makeA&quot;
      }
    }
  }]
  </code></pre>
  <p>My idea is to populate a <code>VehicleModel</code> object which contains a reference to a <code>VehicleMake</code> object.</p>
  <pre><code>class VehicleModel {
      public $id;
      public $code;
      public $model;
      public $make; // VehicleMake
  }
  </code></pre>
  <p>Here is what I do:</p>
  <pre><code>// Retrieve data in JSON
  $data = ...
  $serializer = new Serializer([new ObjectNormalizer(), new ArrayDenormalizer()], [new JsonEncoder()]);
  $models = $serializer-&gt;deserialize($data, '\Namespace\VehicleModel[]', 'json');
  </code></pre>
  <p>In result, my object <code>VehicleModel</code> is correctly populated but <code>$make</code> is logically a key/value array. Here I want a <code>VehicleMake</code> instead.</p>
  <p>Is there a way to do that?</p>