title: How to serialize objects so their nested entities are represented by a id?
body: <p>Let's say there are objects <strong><em>A</em></strong>, <strong><em>B</em></strong> and <strong><em>C</em></strong>. They're all Doctrine ORM entities.</p>
  
  <p>Object <strong><em>A</em></strong> is the aggregate root - it's a composite of <strong><em>B</em></strong> and <strong><em>C</em></strong> objects.
  Serializing object <strong><em>A</em></strong> returns it's own data and also properties of <strong><em>B</em></strong> and <strong><em>C</em></strong>. This is something I want to change in the most graceful way possible.</p>
  
  <p>Object <strong><em>A</em></strong> should serialize in a way that retains it's properties but represents <strong><em>B</em></strong> and <strong><em>C</em></strong> with one of their properties - in this case their id. JSON example:</p>
  
  <pre class="lang-js prettyprint-override"><code>{
    "objA": {
      "property": true,
      "objB": 10,
      "objC": "a1c81b5a-6ecd-4c40-a541-f779b907418c",
    }
  }
  </code></pre>
  
  <p>I was wondering what is a good way that could be used system-wide to achieve that. </p>
  
  <p>This is how I want to represent nested entities in almost every situation in my application - someone suggested me to implement Presentation Models or ViewModels for every case, but isn't there a way to configure this in Doctrine or Symfony's serializer?  </p>