@@ -655,7 +655,7 @@ When serializing, you can set a callback to format a specific object property::
655655 $encoder = new JsonEncoder();
656656
657657 // all callback parameters are optional (you can omit the ones you don't use)
658- $callback = function ($innerObject, $outerObject, string $attributeName, string $format = null, array $context = []) {
658+ $dateCallback = function ($innerObject, $outerObject, string $attributeName, string $format = null, array $context = []) {
659659 return $innerObject instanceof \DateTime ? $innerObject->format(\DateTime::ISO8601) : '';
660660 };
661661
@@ -677,6 +677,11 @@ When serializing, you can set a callback to format a specific object property::
677677 $serializer->serialize($person, 'json');
678678 // Output: {"name":"cordoval", "age": 34, "createdAt": "2014-03-22T09:43:12-0500"}
679679
680+ .. deprecated :: 4.2
681+
682+ The :method: `Symfony\\ Component\\ Serializer\\ Normalizer\\ AbstractNormalizer::setCallbacks ` is deprecated since
683+ Symfony 4.2, use the "callbacks" key of the context instead.
684+
680685.. _component-serializer-normalizers :
681686
682687Normalizers
@@ -947,15 +952,9 @@ when such a case is encountered::
947952
948953 echo $serializer->serialize($organization, 'json'); // Throws a CircularReferenceException
949954
950- The ``setCircularReferenceLimit() `` method of this normalizer sets the number
951- of times it will serialize the same object before considering it a circular
952- reference. Its default value is ``1 ``.
953-
954- .. deprecated :: 4.2
955-
956- The :method: `Symfony\\ Component\\ Serializer\\ Normalizer\\ AbstractNormalizer::setCircularReferenceHandler `
957- method is deprecated since Symfony 4.2. Use the ``circular_reference_handler ``
958- key of the context instead.
955+ The key ``circular_reference_limit `` in the default context sets the number of
956+ times it will serialize the same object before considering it a circular
957+ reference. The default value is ``1 ``.
959958
960959Instead of throwing an exception, circular references can also be handled
961960by custom callables. This is especially useful when serializing entities
@@ -973,6 +972,12 @@ having unique identifiers::
973972 var_dump($serializer->serialize($org, 'json'));
974973 // {"name":"Les-Tilleuls.coop","members":[{"name":"K\u00e9vin", organization: "Les-Tilleuls.coop"}]}
975974
975+ .. deprecated :: 4.2
976+
977+ The :method: `Symfony\\ Component\\ Serializer\\ Normalizer\\ AbstractNormalizer::setCircularReferenceHandler `
978+ method is deprecated since Symfony 4.2. Use the ``circular_reference_handler ``
979+ key of the context instead.
980+
976981Handling Serialization Depth
977982----------------------------
978983
@@ -1100,11 +1105,16 @@ having unique identifiers::
11001105 $level2->child = $level3;
11011106
11021107 $classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
1103- $normalizer = new ObjectNormalizer($classMetadataFactory);
1108+
11041109 // all callback parameters are optional (you can omit the ones you don't use)
1105- $normalizer->setMaxDepthHandler( function ($innerObject, $outerObject, string $attributeName, string $format = null, array $context = []) {
1110+ $maxDepthHandler = function ($innerObject, $outerObject, string $attributeName, string $format = null, array $context = []) {
11061111 return '/foos/'.$innerObject->id;
1107- });
1112+ };
1113+
1114+ $defaultContext = [
1115+ AbstractObjectNormalizer::MAX_DEPTH_HANDLER => $maxDepthHandler,
1116+ ];
1117+ $normalizer = new ObjectNormalizer($classMetadataFactory, null, null, null, null, null, $defaultContext);
11081118
11091119 $serializer = new Serializer([$normalizer]);
11101120
@@ -1119,6 +1129,12 @@ having unique identifiers::
11191129 ];
11201130 */
11211131
1132+ .. deprecated :: 4.2
1133+
1134+ The :method: `Symfony\\ Component\\ Serializer\\ Normalizer\\ AbstractNormalizer::setMaxDepthHandler `
1135+ method is deprecated since Symfony 4.2. Use the ``max_depth_handler ``
1136+ key of the context instead.
1137+
11221138Handling Arrays
11231139---------------
11241140
0 commit comments