@@ -638,7 +638,7 @@ When serializing, you can set a callback to format a specific object property::
638638 $encoder = new JsonEncoder();
639639
640640 // all callback parameters are optional (you can omit the ones you don't use)
641- $callback = function ($innerObject, $outerObject, string $attributeName, string $format = null, array $context = []) {
641+ $dateCallback = function ($innerObject, $outerObject, string $attributeName, string $format = null, array $context = []) {
642642 return $innerObject instanceof \DateTime ? $innerObject->format(\DateTime::ISO8601) : '';
643643 };
644644
@@ -660,6 +660,11 @@ When serializing, you can set a callback to format a specific object property::
660660 $serializer->serialize($person, 'json');
661661 // Output: {"name":"cordoval", "age": 34, "createdAt": "2014-03-22T09:43:12-0500"}
662662
663+ .. deprecated :: 4.2
664+
665+ The :method: `Symfony\\ Component\\ Serializer\\ Normalizer\\ AbstractNormalizer::setCallbacks ` is deprecated since
666+ Symfony 4.2, use the "callbacks" key of the context instead.
667+
663668.. _component-serializer-normalizers :
664669
665670Normalizers
@@ -926,9 +931,9 @@ when such a case is encountered::
926931
927932 echo $serializer->serialize($organization, 'json'); // Throws a CircularReferenceException
928933
929- The `` setCircularReferenceLimit() `` method of this normalizer sets the number
930- of times it will serialize the same object before considering it a circular
931- reference. Its default value is ``1 ``.
934+ The key `` circular_reference_limit `` in the default context sets the number of
935+ times it will serialize the same object before considering it a circular
936+ reference. The default value is ``1 ``.
932937
933938Instead of throwing an exception, circular references can also be handled
934939by custom callables. This is especially useful when serializing entities
@@ -946,6 +951,12 @@ having unique identifiers::
946951 var_dump($serializer->serialize($org, 'json'));
947952 // {"name":"Les-Tilleuls.coop","members":[{"name":"K\u00e9vin", organization: "Les-Tilleuls.coop"}]}
948953
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.
959+
949960Handling Serialization Depth
950961----------------------------
951962
@@ -1073,11 +1084,16 @@ having unique identifiers::
10731084 $level2->child = $level3;
10741085
10751086 $classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
1076- $normalizer = new ObjectNormalizer($classMetadataFactory);
1087+
10771088 // all callback parameters are optional (you can omit the ones you don't use)
1078- $normalizer->setMaxDepthHandler( function ($innerObject, $outerObject, string $attributeName, string $format = null, array $context = []) {
1089+ $maxDepthHandler = function ($innerObject, $outerObject, string $attributeName, string $format = null, array $context = []) {
10791090 return '/foos/'.$innerObject->id;
1080- });
1091+ };
1092+
1093+ $defaultContext = [
1094+ AbstractObjectNormalizer::MAX_DEPTH_HANDLER => $maxDepthHandler,
1095+ ];
1096+ $normalizer = new ObjectNormalizer($classMetadataFactory, null, null, null, null, null, $defaultContext);
10811097
10821098 $serializer = new Serializer([$normalizer]);
10831099
@@ -1092,6 +1108,12 @@ having unique identifiers::
10921108 ];
10931109 */
10941110
1111+ .. deprecated :: 4.2
1112+
1113+ The :method: `Symfony\\ Component\\ Serializer\\ Normalizer\\ AbstractNormalizer::setMaxDepthHandler `
1114+ method is deprecated since Symfony 4.2. Use the ``max_depth_handler ``
1115+ key of the context instead.
1116+
10951117Handling Arrays
10961118---------------
10971119
0 commit comments