title: Remove proxies from Json Response Symfony2
body: <p>I'm working in Symfony2 application and what I'm trying to do is to remove unwanted fields from response and show only fields that I want.</p>
  
  <p>My JSON looks like this:</p>
  
  <pre><code>[
    {
      "id": 1,
      "title": "Granit",
      "typeId": {
        "id": 1,
        "name": "X or Y",
        "acroname": "xory",
        "__initializer__": null,
        "__cloner__": null,
        "__isInitialized__": true
      },
      "pushDate": {
        "timezone": {
          "name": "Europe/Berlin",
          "location": {
            "country_code": "DE",
            "latitude": 52.5,
            "longitude": 13.36666,
            "comments": "most locations"
          }
        },
        "offset": 7200,
        "timestamp": 1460584800
      },
      "addedAt": {
        "timezone": {
          "name": "Europe/Berlin",
          "location": {
            "country_code": "DE",
            "latitude": 52.5,
            "longitude": 13.36666,
            "comments": "most locations"
          }
        },
        "offset": 7200,
        "timestamp": 1460548644
      },
      "deviceToShow": {
        "id": 2,
        "name": "Mobile",
        "__initializer__": null,
        "__cloner__": null,
        "__isInitialized__": true
      },
      "statusSurvey": false,
      "slides": [
        {
          "id": 1,
          "title": "First Question",
          "picture1": "160413015724bazinga2.jpg",
          "picture2": "160413015724th.jpg",
          "idSurvey": 1,
          "absolutePathpic1": "C:\\xampp\\htdocs\\stu-wrapper\\src\\AppBundle\\Entity/../../../web/uploads/slideSurvey/160413015724bazinga2.jpg",
          "webPathpic1": "uploads/slideSurvey/160413015724bazinga2.jpg",
          "absolutePathpic2": "C:\\xampp\\htdocs\\stu-wrapper\\src\\AppBundle\\Entity/../../../web/uploads/slideSurvey/160413015724th.jpg",
          "webPathpic2": "uploads/slideSurvey/160413015724th.jpg",
          "file": null,
          "file1": null
        }
      ],
      "categories": []
    }
  ]
  </code></pre>
  
  <p>I want to remove fields like  "<strong>initializer</strong>": null,"<strong>cloner</strong>": null, "<strong>isInitialized</strong>": true and hide timezone object and show only "timestamp".</p>
  
  <p>Here is my controller where I'm doing serializing and creating Json Response. </p>
  
  <pre><code>public function getAction()
      {
          $em = $this-&gt;getDoctrine ()-&gt;getManager ();
          $survey = $em-&gt;getRepository ( 'AppBundle:Survey' )-&gt;findAll ();
  
          if ( !$survey ) {
              throw $this-&gt;createNotFoundException ( 'Data not found.' );
          }
          $encoder = new JsonEncoder();
          $normalizer = new ObjectNormalizer();
          $normalizer-&gt;setCircularReferenceHandler ( function ( $survey ) {
              return $survey-&gt;getid ();
          } );
  
  
          $serializer = new Serializer( array ( $normalizer ), array ( $encoder ) );
  
          $jsonContent = $serializer-&gt;serialize ( $survey, 'json' );
  
          return new Response( $jsonContent );
      }
  </code></pre>
  
  <p>Thank you.</p>