@@ -13,9 +13,9 @@ simple schema.
1313
1414.. image :: /_images/components/serializer/serializer_workflow.png
1515
16- As you can see in the picture above, an array is used as a man in
17- the middle . This way, Encoders will only deal with turning specific
18- **formats ** into **arrays ** and vice versa. The same way, Normalizers
16+ As you can see in the picture above, an array is used as an intermediary between
17+ objects and serialized contents . This way, encoders will only deal with turning
18+ specific **formats ** into **arrays ** and vice versa. The same way, Normalizers
1919will deal with turning specific **objects ** into **arrays ** and vice versa.
2020
2121Serialization is a complex topic. This component may not cover all your use cases out of the box,
@@ -63,13 +63,13 @@ Serializing an Object
6363For the sake of this example, assume the following class already
6464exists in your project::
6565
66- namespace Acme ;
66+ namespace App\Model ;
6767
6868 class Person
6969 {
7070 private $age;
7171 private $name;
72- private $sportsman ;
72+ private $sportsperson ;
7373 private $createdAt;
7474
7575 // Getters
@@ -89,9 +89,9 @@ exists in your project::
8989 }
9090
9191 // Issers
92- public function isSportsman ()
92+ public function isSportsperson ()
9393 {
94- return $this->sportsman ;
94+ return $this->sportsperson ;
9595 }
9696
9797 // Setters
@@ -105,9 +105,9 @@ exists in your project::
105105 $this->age = $age;
106106 }
107107
108- public function setSportsman($sportsman )
108+ public function setSportsperson($sportsperson )
109109 {
110- $this->sportsman = $sportsman ;
110+ $this->sportsperson = $sportsperson ;
111111 }
112112
113113 public function setCreatedAt($createdAt)
@@ -119,14 +119,14 @@ exists in your project::
119119Now, if you want to serialize this object into JSON, you only need to
120120use the Serializer service created before::
121121
122- $person = new Acme \Person();
122+ $person = new App\Model \Person();
123123 $person->setName('foo');
124124 $person->setAge(99);
125- $person->setSportsman (false);
125+ $person->setSportsperson (false);
126126
127127 $jsonContent = $serializer->serialize($person, 'json');
128128
129- // $jsonContent contains {"name":"foo","age":99,"sportsman ":false}
129+ // $jsonContent contains {"name":"foo","age":99,"sportsperson ":false}
130130
131131 echo $jsonContent; // or return it in a Response
132132
@@ -140,13 +140,13 @@ Deserializing an Object
140140You'll now learn how to do the exact opposite. This time, the information
141141of the ``Person `` class would be encoded in XML format::
142142
143- use Acme \Person;
143+ use App\Model \Person;
144144
145145 $data = <<<EOF
146146 <person>
147147 <name>foo</name>
148148 <age>99</age>
149- <sportsman >false</sportsman >
149+ <sportsperson >false</sportsperson >
150150 </person>
151151 EOF;
152152
@@ -187,7 +187,7 @@ The serializer can also be used to update an existing object::
187187 $person = new Person();
188188 $person->setName('bar');
189189 $person->setAge(99);
190- $person->setSportsman (true);
190+ $person->setSportsperson (true);
191191
192192 $data = <<<EOF
193193 <person>
@@ -197,7 +197,7 @@ The serializer can also be used to update an existing object::
197197 EOF;
198198
199199 $serializer->deserialize($data, Person::class, 'xml', array('object_to_populate' => $person));
200- // $person = Acme\ Person(name: 'foo', age: '69', sportsman : true)
200+ // $person = App\Model\ Person(name: 'foo', age: '69', sportsperson : true)
201201
202202This is a common need when working with an ORM.
203203
@@ -400,7 +400,7 @@ method on the normalizer definition::
400400 $encoder = new JsonEncoder();
401401
402402 $serializer = new Serializer(array($normalizer), array($encoder));
403- $serializer->serialize($person, 'json'); // Output: {"name":"foo","sportsman ":false}
403+ $serializer->serialize($person, 'json'); // Output: {"name":"foo","sportsperson ":false}
404404
405405.. _component-serializer-converting-property-names-when-serializing-and-deserializing :
406406
@@ -512,8 +512,8 @@ Serializing Boolean Attributes
512512------------------------------
513513
514514If you are using isser methods (methods prefixed by ``is ``, like
515- ``Acme\ Person::isSportsman () ``), the Serializer component will automatically
516- detect and use it to serialize related attributes.
515+ ``App\Model\ Person::isSportsperson () ``), the Serializer component will
516+ automatically detect and use it to serialize related attributes.
517517
518518The ``ObjectNormalizer `` also takes care of methods starting with ``has ``, ``add ``
519519and ``remove ``.
@@ -523,7 +523,7 @@ Using Callbacks to Serialize Properties with Object Instances
523523
524524When serializing, you can set a callback to format a specific object property::
525525
526- use Acme \Person;
526+ use App\Model \Person;
527527 use Symfony\Component\Serializer\Encoder\JsonEncoder;
528528 use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer;
529529 use Symfony\Component\Serializer\Serializer;
@@ -860,7 +860,7 @@ Here, we set it to 2 for the ``$child`` property:
860860 /**
861861 * @MaxDepth(2)
862862 */
863- public $foo ;
863+ public $child ;
864864
865865 // ...
866866 }
@@ -869,7 +869,7 @@ Here, we set it to 2 for the ``$child`` property:
869869
870870 Acme\MyObj :
871871 attributes :
872- foo :
872+ child :
873873 max_depth : 2
874874
875875 .. code-block :: xml
@@ -881,7 +881,7 @@ Here, we set it to 2 for the ``$child`` property:
881881 http://symfony.com/schema/dic/serializer-mapping/serializer-mapping-1.0.xsd"
882882 >
883883 <class name =" Acme\MyObj" >
884- <attribute name =" foo " max-depth =" 2" />
884+ <attribute name =" child " max-depth =" 2" />
885885 </class >
886886 </serializer >
887887
0 commit comments