@@ -545,7 +545,7 @@ When serializing, you can set a callback to format a specific object property::
545545 $encoder = new JsonEncoder();
546546 $normalizer = new GetSetMethodNormalizer();
547547
548- $callback = function ($innerObject, $outerObject, string $attributeName, string $format = null, array $context = null ) {
548+ $callback = function ($innerObject, $outerObject, string $attributeName, string $format = null, array $context = array() ) {
549549 // Every parameters can be omitted if not used
550550 return $dateTime instanceof \DateTime ? $dateTime->format(\DateTime::ISO8601) : '';
551551 };
@@ -832,14 +832,18 @@ having unique identifiers::
832832 $encoder = new JsonEncoder();
833833 $normalizer = new ObjectNormalizer();
834834
835- $normalizer->setCircularReferenceHandler(function ($object) {
835+ $normalizer->setCircularReferenceHandler(function ($object, string $format = null, array $context = array()) {
836+ // Every parameters can be omitted if not used
836837 return $object->getName();
837838 });
838839
839840 $serializer = new Serializer(array($normalizer), array($encoder));
840841 var_dump($serializer->serialize($org, 'json'));
841842 // {"name":"Les-Tilleuls.coop","members":[{"name":"K\u00e9vin", organization: "Les-Tilleuls.coop"}]}
842843
844+ .. versionadded :: 4.2
845+ The ``$format `` and ``$context `` parameters of ``setCircularReferenceHandler() `` were introduced in Symfony 4.2.
846+
843847Handling Serialization Depth
844848----------------------------
845849
@@ -968,7 +972,7 @@ having unique identifiers::
968972
969973 $classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
970974 $normalizer = new ObjectNormalizer($classMetadataFactory);
971- $normalizer->setMaxDepthHandler(function ($innerObject, $outerObject, string $attributeName, string $format = null, array $context = null ) {
975+ $normalizer->setMaxDepthHandler(function ($innerObject, $outerObject, string $attributeName, string $format = null, array $context = array() ) {
972976 // Every parameters can be omitted if not used
973977 return '/foos/'.$innerObject->id;
974978 });
0 commit comments