Use the “circular_reference_handler” key of the context instead symfony 4.2
问题 I have to serialize an object and I get the ever so common "circular reference error" I have used the old Symfony method : $normalizer = new ObjectNormalizer(); // Add Circular reference handler $normalizer->setCircularReferenceHandler(function ($object) { return $object->getId(); }); $normalizers = array($normalizer); $encoders = [new JsonEncoder()]; $serializer = new Serializer($normalizers, $encoders); This work but as of Symfony 4.2 I get the exception you see in the title of this