A circular reference has been detected when serializing the object of class “App\Entity\User” (configured limit: 1)

前端 未结 2 922
夕颜
夕颜 2021-01-19 07:25

I am faced with a problem that gives me this error:

A circular reference has been detected when serializing the object of class "App\\Entity\\User&q

2条回答
  •  孤独总比滥情好
    2021-01-19 08:13

    In my case I've fixed injecting the serializer service instead of creating a new Serializer instance in the controller method.

    use Symfony\Component\Serializer\SerializerInterface;
    
    //...
    public function createOrder(Request $request, SerializerInterface $serializer)
    {
        //...
        $json = $serializer->serialize($order, 'json', ['groups' => ['normal']]);
        //...
    }
    

提交回复
热议问题