I'm trying to convert an entity to a associative array.
It seems that the method toArray() is not available for entity objects.
Reading Symfony doc, it seems I should use the SerializerInterface.
After enabling it, I can't seems to find the right syntax to convert my entity into an associative array.
Can someone correct my code please?
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\Serializer\SerializerInterface;
// -----------------------
public function salleAction(Request $request, Projet $projet, SerializerInterface $serializer) {
return this->json(array(
'projet'=>$serializer->serialize($projet, new ObjectNormalizer())
));
}
With the code above, I'm getting this error message
Warning: Illegal offset type in isset or empty
If I replace new ObjectNormalizer() by 'jsons', I'm getting the next error message:
A circular reference has been detected when serializing the object of class "AppBundle\Entity\Projet" (configured limit: 1)