@@ -168,7 +168,7 @@ needs three parameters:
168168
169169By default, additional attributes that are not mapped to the denormalized object
170170will be ignored by the Serializer component. If you prefer to throw an exception
171- when this happens, set the ``allow_extra_attributes `` context option to
171+ when this happens, set the ``AbstractNormalizer::ALLOW_EXTRA_ATTRIBUTES `` context option to
172172``false `` and provide an object that implements ``ClassMetadataFactoryInterface ``
173173when constructing the normalizer::
174174
@@ -188,7 +188,7 @@ when constructing the normalizer::
188188 // this will throw a Symfony\Component\Serializer\Exception\ExtraAttributesException
189189 // because "city" is not an attribute of the Person class
190190 $person = $serializer->deserialize($data, 'App\Model\Person', 'xml', [
191- 'allow_extra_attributes' => false,
191+ AbstractNormalizer::ALLOW_EXTRA_ATTRIBUTES => false,
192192 ]);
193193
194194Deserializing in an Existing Object
@@ -209,12 +209,12 @@ The serializer can also be used to update an existing object::
209209 </person>
210210 EOF;
211211
212- $serializer->deserialize($data, Person::class, 'xml', ['object_to_populate' => $person]);
212+ $serializer->deserialize($data, Person::class, 'xml', [AbstractNormalizer::OBJECT_TO_POPULATE => $person]);
213213 // $person = App\Model\Person(name: 'foo', age: '69', sportsperson: true)
214214
215215This is a common need when working with an ORM.
216216
217- The ``OBJECT_TO_POPULATE `` is only used for the top level object. If that object
217+ The ``AbstractNormalizer:: OBJECT_TO_POPULATE `` is only used for the top level object. If that object
218218is the root of a tree structure, all child elements that exist in the
219219normalized data will be re-created with new instances.
220220
@@ -372,6 +372,7 @@ Selecting Specific Attributes
372372
373373It is also possible to serialize only a set of specific attributes::
374374
375+ use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
375376 use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
376377 use Symfony\Component\Serializer\Serializer;
377378
@@ -399,7 +400,7 @@ It is also possible to serialize only a set of specific attributes::
399400
400401 $serializer = new Serializer([new ObjectNormalizer()]);
401402
402- $data = $serializer->normalize($user, null, ['attributes' => ['familyName', 'company' => ['name']]]);
403+ $data = $serializer->normalize($user, null, [AbstractNormalizer::ATTRIBUTES => ['familyName', 'company' => ['name']]]);
403404 // $data = ['familyName' => 'Dunglas', 'company' => ['name' => 'Les-Tilleuls.coop']];
404405
405406Only attributes that are not ignored (see below) are available.
@@ -411,11 +412,12 @@ Ignoring Attributes
411412-------------------
412413
413414As an option, there's a way to ignore attributes from the origin object.
414- To remove those attributes provide an array via the ``ignored_attributes ``
415+ To remove those attributes provide an array via the ``AbstractNormalizer::IGNORED_ATTRIBUTES ``
415416key in the ``context `` parameter of the desired serializer method::
416417
417418 use Acme\Person;
418419 use Symfony\Component\Serializer\Encoder\JsonEncoder;
420+ use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
419421 use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
420422 use Symfony\Component\Serializer\Serializer;
421423
@@ -427,7 +429,7 @@ key in the ``context`` parameter of the desired serializer method::
427429 $encoder = new JsonEncoder();
428430
429431 $serializer = new Serializer([$normalizer], [$encoder]);
430- $serializer->serialize($person, 'json', ['ignored_attributes' => ['age']]); // Output: {"name":"foo"}
432+ $serializer->serialize($person, 'json', [AbstractNormalizer::IGNORED_ATTRIBUTES => ['age']]); // Output: {"name":"foo"}
431433
432434.. _component-serializer-converting-property-names-when-serializing-and-deserializing :
433435
@@ -843,7 +845,7 @@ Skipping ``null`` Values
843845------------------------
844846
845847By default, the Serializer will preserve properties containing a ``null `` value.
846- You can change this behavior by setting the ``skip_null_values `` context option
848+ You can change this behavior by setting the ``AbstractObjectNormalizer::SKIP_NULL_VALUES `` context option
847849to ``true ``::
848850
849851 $dummy = new class {
@@ -852,7 +854,7 @@ to ``true``::
852854 };
853855
854856 $normalizer = new ObjectNormalizer();
855- $result = $normalizer->normalize($dummy, 'json', ['skip_null_values' => true]);
857+ $result = $normalizer->normalize($dummy, 'json', [AbstractObjectNormalizer::SKIP_NULL_VALUES => true]);
856858 // ['bar' => 'notNull']
857859
858860.. _component-serializer-handling-circular-references :
@@ -1027,11 +1029,11 @@ in a Symfony application. When using the standalone component, refer to
10271029:ref: `the groups documentation <component-serializer-attributes-groups >` to
10281030learn how to do that.
10291031
1030- The check is only done if the ``enable_max_depth `` key of the serializer context
1032+ The check is only done if the ``AbstractObjectNormalizer::ENABLE_MAX_DEPTH `` key of the serializer context
10311033is set to ``true ``. In the following example, the third level is not serialized
10321034because it is deeper than the configured maximum depth of 2::
10331035
1034- $result = $serializer->normalize($level1, null, ['enable_max_depth' => true]);
1036+ $result = $serializer->normalize($level1, null, [AbstractObjectNormalizer::ENABLE_MAX_DEPTH => true]);
10351037 /*
10361038 $result = [
10371039 'foo' => 'level1',
@@ -1052,6 +1054,7 @@ having unique identifiers::
10521054 use Symfony\Component\Serializer\Annotation\MaxDepth;
10531055 use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
10541056 use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
1057+ use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer;
10551058 use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
10561059 use Symfony\Component\Serializer\Serializer;
10571060
@@ -1090,7 +1093,7 @@ having unique identifiers::
10901093
10911094 $serializer = new Serializer([$normalizer]);
10921095
1093- $result = $serializer->normalize($level1, null, [ObjectNormalizer ::ENABLE_MAX_DEPTH => true]);
1096+ $result = $serializer->normalize($level1, null, [AbstractObjectNormalizer ::ENABLE_MAX_DEPTH => true]);
10941097 /*
10951098 $result = [
10961099 'id' => 1,
@@ -1220,6 +1223,7 @@ If the class constructor defines arguments, as usually happens with
12201223arguments are missing. In those cases, use the ``default_constructor_arguments ``
12211224context option::
12221225
1226+ use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
12231227 use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
12241228 use Symfony\Component\Serializer\Serializer;
12251229
@@ -1241,7 +1245,7 @@ context option::
12411245 $data = $serializer->denormalize(
12421246 ['foo' => 'Hello'],
12431247 'MyObj',
1244- ['default_constructor_arguments' => [
1248+ [AbstractNormalizer::DEFAULT_CONSTRUCTOR_ARGUMENTS => [
12451249 'MyObj' => ['foo' => '', 'bar' => ''],
12461250 ]]
12471251 );
0 commit comments