Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4158b30

Browse filesBrowse files
committed
minor #9795 Use gender-neutral language in the main Serializer article (javiereguiluz)
This PR was squashed before being merged into the 2.7 branch (closes #9795). Discussion ---------- Use gender-neutral language in the main Serializer article Commits ------- 1e4bc44 Use gender-neutral language in the main Serializer article
2 parents b7ce0a9 + 1e4bc44 commit 4158b30
Copy full SHA for 4158b30

File tree

1 file changed

+20
-20
lines changed
Filter options

1 file changed

+20
-20
lines changed

‎components/serializer.rst

Copy file name to clipboardExpand all lines: components/serializer.rst
+20-20Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ simple schema.
1616

1717
.. image:: /_images/components/serializer/serializer_workflow.png
1818

19-
As you can see in the picture above, an array is used as a man in
20-
the middle. This way, Encoders will only deal with turning specific
21-
**formats** into **arrays** and vice versa. The same way, Normalizers
19+
As you can see in the picture above, an array is used as an intermediary between
20+
objects and serialized contents. This way, encoders will only deal with turning
21+
specific **formats** into **arrays** and vice versa. The same way, Normalizers
2222
will deal with turning specific **objects** into **arrays** and vice versa.
2323

2424
Serialization is a complex topic. This component may not cover all your use cases out of the box,
@@ -66,13 +66,13 @@ Serializing an Object
6666
For the sake of this example, assume the following class already
6767
exists in your project::
6868

69-
namespace Acme;
69+
namespace App\Model;
7070

7171
class Person
7272
{
7373
private $age;
7474
private $name;
75-
private $sportsman;
75+
private $sportsperson;
7676
private $createdAt;
7777

7878
// Getters
@@ -92,9 +92,9 @@ exists in your project::
9292
}
9393

9494
// Issers
95-
public function isSportsman()
95+
public function isSportsperson()
9696
{
97-
return $this->sportsman;
97+
return $this->sportsperson;
9898
}
9999

100100
// Setters
@@ -108,9 +108,9 @@ exists in your project::
108108
$this->age = $age;
109109
}
110110

111-
public function setSportsman($sportsman)
111+
public function setSportsperson($sportsperson)
112112
{
113-
$this->sportsman = $sportsman;
113+
$this->sportsperson = $sportsperson;
114114
}
115115

116116
public function setCreatedAt($createdAt)
@@ -122,14 +122,14 @@ exists in your project::
122122
Now, if you want to serialize this object into JSON, you only need to
123123
use the Serializer service created before::
124124

125-
$person = new Acme\Person();
125+
$person = new App\Model\Person();
126126
$person->setName('foo');
127127
$person->setAge(99);
128-
$person->setSportsman(false);
128+
$person->setSportsperson(false);
129129

130130
$jsonContent = $serializer->serialize($person, 'json');
131131

132-
// $jsonContent contains {"name":"foo","age":99,"sportsman":false}
132+
// $jsonContent contains {"name":"foo","age":99,"sportsperson":false}
133133

134134
echo $jsonContent; // or return it in a Response
135135

@@ -143,13 +143,13 @@ Deserializing an Object
143143
You'll now learn how to do the exact opposite. This time, the information
144144
of the ``Person`` class would be encoded in XML format::
145145

146-
use Acme\Person;
146+
use App\Model\Person;
147147

148148
$data = <<<EOF
149149
<person>
150150
<name>foo</name>
151151
<age>99</age>
152-
<sportsman>false</sportsman>
152+
<sportsperson>false</sportsperson>
153153
</person>
154154
EOF;
155155

@@ -171,7 +171,7 @@ The serializer can also be used to update an existing object::
171171
$person = new Person();
172172
$person->setName('bar');
173173
$person->setAge(99);
174-
$person->setSportsman(true);
174+
$person->setSportsperson(true);
175175

176176
$data = <<<EOF
177177
<person>
@@ -181,7 +181,7 @@ The serializer can also be used to update an existing object::
181181
EOF;
182182

183183
$serializer->deserialize($data, Person::class, 'xml', array('object_to_populate' => $person));
184-
// $person = Acme\Person(name: 'foo', age: '69', sportsman: true)
184+
// $person = App\Model\Person(name: 'foo', age: '69', sportsperson: true)
185185

186186
This is a common need when working with an ORM.
187187

@@ -356,7 +356,7 @@ method on the normalizer definition::
356356
$encoder = new JsonEncoder();
357357

358358
$serializer = new Serializer(array($normalizer), array($encoder));
359-
$serializer->serialize($person, 'json'); // Output: {"name":"foo","sportsman":false}
359+
$serializer->serialize($person, 'json'); // Output: {"name":"foo","sportsperson":false}
360360

361361
Converting Property Names when Serializing and Deserializing
362362
------------------------------------------------------------
@@ -474,8 +474,8 @@ Serializing Boolean Attributes
474474
------------------------------
475475

476476
If you are using isser methods (methods prefixed by ``is``, like
477-
``Acme\Person::isSportsman()``), the Serializer component will automatically
478-
detect and use it to serialize related attributes.
477+
``App\Model\Person::isSportsperson()``), the Serializer component will
478+
automatically detect and use it to serialize related attributes.
479479

480480
The ``ObjectNormalizer`` also takes care of methods starting with ``has``, ``add``
481481
and ``remove``.
@@ -485,7 +485,7 @@ Using Callbacks to Serialize Properties with Object Instances
485485

486486
When serializing, you can set a callback to format a specific object property::
487487

488-
use Acme\Person;
488+
use App\Model\Person;
489489
use Symfony\Component\Serializer\Encoder\JsonEncoder;
490490
use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer;
491491
use Symfony\Component\Serializer\Serializer;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.