Skip to content

Commit 39e9632

Browse files
committed
[symfony#1684] Adding the index/map, proofreading and adding a little bit more to the new serializer component doc
1 parent 496ed4a commit 39e9632

File tree

3 files changed

+33
-13
lines changed

3 files changed

+33
-13
lines changed

components/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ The Components
1616
locale
1717
process
1818
routing
19+
serializer
1920
templating
2021
yaml
2122

components/map.rst.inc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@
5757

5858
* :doc:`/components/routing`
5959

60+
* **The Serializer Component**
61+
62+
* :doc:`/components/serializer`
63+
6064
* **The Templating Component**
6165

6266
* :doc:`/components/templating`

components/serializer.rst

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,23 @@
55
The Serializer Component
66
========================
77

8-
The Serializer Component is meant to be used to turn Objects into a
8+
The Serializer Component is meant to be used to turn objects into a
99
specific format (XML, JSON, Yaml, ...) and the other way around.
1010

11-
In order to do so, the Serializer Components follows the following
11+
In order to do so, the Serializer Component follows the following
1212
simple schema.
1313

1414
.. image:: /images/components/serializer/serializer_workflow.png
1515

1616
As you can see in the picture above, an array is used as a man in
17-
the middle. This way, Normalizers will only deal with turning specific
17+
the middle. This way, Serializers will only deal with turning specific
1818
**formats** into **arrays** and vice versa. The same way, Normalizers
1919
will deal with turning specific **objects** into **arrays** and vice versa.
2020

21+
Serialization is a complicated topic, and while this component may not work
22+
in all cases, it can be a useful tool while developing tools to serialize
23+
and deserialize your objects.
24+
2125
Installation
2226
------------
2327

@@ -31,24 +35,23 @@ Usage
3135
-----
3236

3337
Using the Serializer component is really simple. We just need to set up
34-
the :class:`Symfony\\Component\\Serializer\\Serializer` specifying
35-
what Encoders and Normalizer are going to be available::
38+
the :class:`Symfony\\Component\\Serializer\\Serializer` specifying
39+
which Encoders and Normalizer are going to be available::
3640

3741
use Symfony\Component\Serializer\Serializer;
3842
use Symfony\Component\Serializer\Encoder\XmlEncoder;
3943
use Symfony\Component\Serializer\Encoder\JsonEncoder;
4044
use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer;
4145

42-
$encoders = array(new XmlEncoder(), new JsonEncoder() );
46+
$encoders = array(new XmlEncoder(), new JsonEncoder());
4347
$normalizers = array(new GetSetMethodNormalizer());
4448

4549
$serializer = new Serializer($normalizers, $encoders);
4650

47-
4851
Serializing an object
4952
~~~~~~~~~~~~~~~~~~~~~
5053

51-
For the sake of this example, let's ssume the following class already
54+
For the sake of this example, let's assume the following class already
5255
exists in our project::
5356

5457
namespace Acme;
@@ -90,12 +93,12 @@ use the Serializer service created before::
9093

9194
$serializer->serialize($person, 'json'); // Output: {"name":"foo","age":99}
9295

93-
The first paramater of the `Serializer::serialize` is the object to be
94-
serialized, the second one will be used to pick the proper encoder,
96+
The first parameter of the :method:`Symfony\\Component\\Serializer\\Serializer::serialize`
97+
is the object to be serialized and the second is used to choose the proper encoder,
9598
in this case :class:`Symfony\\Component\\Serializer\\Encoder\\JsonEncoder`.
9699

97-
Deserializing an object
98-
~~~~~~~~~~~~~~~~~~~~~~~~
100+
Deserializing an Object
101+
~~~~~~~~~~~~~~~~~~~~~~~
99102

100103
Let's see now how to do the exactly the opposite. This time, the information
101104
of the `People` class would be encoded in XML format::
@@ -109,8 +112,20 @@ of the `People` class would be encoded in XML format::
109112

110113
$person = $serializer->deserialize($data,'Acme\Person','xml');
111114

112-
In this case, `Serializer::deserialize` needs three parameters:
115+
In this case, :method:`Symfony\\Component\\Serializer\\Serializer::deserialize`
116+
needs three parameters:
113117

114118
1. The information to be decoded
115119
2. The name of the class this information will be decoded to
116120
3. The encoder used to convert that information into an array
121+
122+
JMSSerializationBundle
123+
----------------------
124+
125+
A popular third-party bundle, `JMSSerializationBundle`_ exists and extends
126+
(and sometimes replaces) the serialization functionality. This includes the
127+
ability to configure how your objects should be serialize/deserialized via
128+
annotations (as well as YML, XML and PHP), integration with the Doctrine ORM,
129+
and handling of other complex cases (e.g. circular references).
130+
131+
.. _`JMSSerializationBundle`: https://github.com/schmittjoh/JMSSerializerBundle

0 commit comments

Comments
 (0)