@@ -545,7 +545,7 @@ When serializing, you can set a callback to format a specific object property::
545
545
$encoder = new JsonEncoder();
546
546
$normalizer = new GetSetMethodNormalizer();
547
547
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() ) {
549
549
// Every parameters can be omitted if not used
550
550
return $dateTime instanceof \DateTime ? $dateTime->format(\DateTime::ISO8601) : '';
551
551
};
@@ -832,14 +832,18 @@ having unique identifiers::
832
832
$encoder = new JsonEncoder();
833
833
$normalizer = new ObjectNormalizer();
834
834
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
836
837
return $object->getName();
837
838
});
838
839
839
840
$serializer = new Serializer(array($normalizer), array($encoder));
840
841
var_dump($serializer->serialize($org, 'json'));
841
842
// {"name":"Les-Tilleuls.coop","members":[{"name":"K\u00e9vin", organization: "Les-Tilleuls.coop"}]}
842
843
844
+ .. versionadded :: 4.2
845
+ The ``$format `` and ``$context `` parameters of ``setCircularReferenceHandler() `` were introduced in Symfony 4.2.
846
+
843
847
Handling Serialization Depth
844
848
----------------------------
845
849
@@ -968,7 +972,7 @@ having unique identifiers::
968
972
969
973
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
970
974
$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() ) {
972
976
// Every parameters can be omitted if not used
973
977
return '/foos/'.$innerObject->id;
974
978
});
0 commit comments