4
4
How to Use the Serializer
5
5
=========================
6
6
7
- Serializing and deserializing to and from objects and different formats (e.g.
8
- JSON or XML) is a very complex topic. Symfony comes with a
9
- :doc: `Serializer Component </components/serializer >`, which gives you some
10
- tools that you can leverage for your solution .
7
+ Symfony provides a serializer to serialize/deserialize to and from objects and
8
+ different formats (e.g. JSON or XML). Before using it, read the
9
+ :doc: `Serializer component docs </components/serializer >` to get familiar with
10
+ its philosophy and the normalizers and encoders terminology .
11
11
12
- In fact, before you start, get familiar with the serializer, normalizers
13
- and encoders by reading the :doc: `Serializer Component </components/serializer >`.
12
+ .. _activating_the_serializer :
14
13
15
- Activating the Serializer
14
+ Installing the Serializer
16
15
-------------------------
17
16
18
- The ``serializer `` service is not available by default. To turn it on, activate
19
- it in your configuration:
17
+ Before using the serializer, run this command to install it in your application:
18
+
19
+ .. code-block :: terminal
20
+
21
+ $ composer require serializer
22
+
23
+ Then, enable the serializer in the framework config:
20
24
21
25
.. configuration-block ::
22
26
@@ -65,7 +69,7 @@ it in your configuration:
65
69
Using the Serializer Service
66
70
----------------------------
67
71
68
- Once enabled, the `` serializer `` service can be injected in any service where
72
+ Once enabled, the serializer service can be injected in any service where
69
73
you need it or it can be used in a controller::
70
74
71
75
// src/Controller/DefaultController.php
@@ -85,7 +89,7 @@ you need it or it can be used in a controller::
85
89
Adding Normalizers and Encoders
86
90
-------------------------------
87
91
88
- Once enabled, the `` serializer `` service will be available in the container
92
+ Once enabled, the serializer service will be available in the container
89
93
and will be loaded with four :ref: `encoders <component-serializer-encoders >`
90
94
(:class: `Symfony\\ Component\\ Serializer\\ Encoder\\ JsonEncoder `,
91
95
:class: `Symfony\\ Component\\ Serializer\\ Encoder\\ XmlEncoder `,
@@ -193,12 +197,12 @@ to your class and choose which groups to use when serializing::
193
197
);
194
198
195
199
In addition to the ``@Groups `` annotation, the Serializer component also
196
- supports Yaml or XML files. These files are automatically loaded when being
200
+ supports YAML or XML files. These files are automatically loaded when being
197
201
stored in one of the following locations:
198
202
199
- * The ``serialization.yml `` or ``serialization.xml `` file in
203
+ * The ``serialization.yaml `` or ``serialization.xml `` file in
200
204
the ``Resources/config/ `` directory of a bundle;
201
- * All ``*.yml `` and ``*.xml `` files in the ``Resources/config/serialization/ ``
205
+ * All ``*.yaml `` and ``*.xml `` files in the ``Resources/config/serialization/ ``
202
206
directory of a bundle.
203
207
204
208
.. _serializer-enabling-metadata-cache :
@@ -302,9 +306,9 @@ take a look at how this bundle works.
302
306
303
307
.. toctree ::
304
308
:maxdepth: 1
305
- :glob:
306
309
307
- serializer/*
310
+ serializer/encoders
311
+ serializer/custom_encoders
308
312
309
313
.. _`APCu` : https://github.com/krakjoe/apcu
310
314
.. _`ApiPlatform` : https://github.com/api-platform/core
0 commit comments