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 question :
use the "circular_reference_handler" key of the context instead Symfony 4.2
I cannot find any reference to this in the Symfony documentation concerning the Serializer.
https://symfony.com/doc/current/components/serializer.html#handling-circular-references
Does any one know how to use this "key of context" instead of the old method?