Hello in my project Symfony i want to convert my Entity to array Json so i choose the serializer for make this , and also i want to ignored some attributes because the convert is too long, so i read the documentation Symfony http://symfony.com/doc/current/components/serializer.html#ignoring-attributes and i copy this code
$flowsites = $this->getDoctrine()->getRepository("QSCORBundle:Flow_Site")->findAll();
$normalizer = new ObjectNormalizer();
$normalizer->setIgnoredAttributes(array('company'));
$encoder = new JsonEncoder();
$serializer = new Serializer(array($normalizer), array($encoder));
$flow_sites = $serializer->serialize($flow_sites, 'json');
var_dump( $flow_sites );
die();
after this the error generate A circular reference has been detected (configured limit: 1) so for resolve this problem i make some change to my code
$normalizer = new ObjectNormalizer(null);
$normalizer->setIgnoredAttributes(array('company', 'origin'));
$normalizer->setCircularReferenceHandler(function ($object) {
return $object->getId();
});
$encoder = new JsonEncoder();
//$serializer = $this->get('serializer');
$serializer = new Serializer(array($normalizer), array($encoder));
$flowsites = $this->getDoctrine()->getRepository("QSCORBundle:Flow_Site")->findAll();
$jsonflowsites = $serializer->serialize( $flowsites, 'json');
var_dump( $jsonflowsites );
die();