44How to Use the Serializer
55=========================
66
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: `SerializerComponent </components/serializer >`, which gives you some
10- tools that you can leverage for your solution .
7+ Symfony provides a serializer toserialize/deserialize to and from objects and
8+ different formats (e.g. JSON or XML). Before using it, read the
9+ :doc: `Serializercomponent docs </components/serializer >` to get familiar with
10+ its philosophy and the normalizers and encoders terminology .
1111
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 :
1413
15- Activating the Serializer
14+ Installing the Serializer
1615-------------------------
1716
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:
2024
2125..configuration-block ::
2226
@@ -65,7 +69,7 @@ it in your configuration:
6569 Using the Serializer Service
6670----------------------------
6771
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
6973you need it or it can be used in a controller::
7074
7175 // src/Controller/DefaultController.php
@@ -85,7 +89,7 @@ you need it or it can be used in a controller::
8589Adding Normalizers and Encoders
8690-------------------------------
8791
88- Once enabled, the`` serializer `` service will be available in the container
92+ Once enabled, the serializer service will be available in the container
8993and will be loaded with four:ref: `encoders <component-serializer-encoders >`
9094(:class: `Symfony\\ Component\\ Serializer\\ Encoder\\ JsonEncoder `,
9195:class: `Symfony\\ Component\\ Serializer\\ Encoder\\ XmlEncoder `,
@@ -193,12 +197,12 @@ to your class and choose which groups to use when serializing::
193197 );
194198
195199In addition to the ``@Groups `` annotation, the Serializer component also
196- supportsYaml or XML files. These files are automatically loaded when being
200+ supportsYAML or XML files. These files are automatically loaded when being
197201stored in one of the following locations:
198202
199- * The ``serialization.yml `` or ``serialization.xml `` file in
203+ * The ``serialization.yaml `` or ``serialization.xml `` file in
200204 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/ ``
202206 directory of a bundle.
203207
204208.. _serializer-enabling-metadata-cache :
@@ -302,9 +306,9 @@ take a look at how this bundle works.
302306
303307..toctree ::
304308:maxdepth: 1
305- :glob:
306309
307- serializer/*
310+ serializer/encoders
311+ serializer/custom_encoders
308312
309313.. _`APCu` :https://github.com/krakjoe/apcu
310314.. _`ApiPlatform` :https://github.com/api-platform/core