Skip to content

Commit 7b96928

Browse files
committed
minor #7493 [Serializer] Add new default normalizers (dunglas)
This PR was submitted for the 3.1 branch but it was squashed and merged into the 3.3 branch instead (closes #7493). Discussion ---------- [Serializer] Add new default normalizers Refactoring of the serializer doc to list new normalizers introduced in 3.1 and enabled by default. Commits ------- f1a5290 [Serializer] Add new default normalizers
2 parents d97b063 + f1a5290 commit 7b96928

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

serializer.rst

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,21 +85,37 @@ you need it or it can be used in a controller::
8585
Adding Normalizers and Encoders
8686
-------------------------------
8787

88-
Once enabled, the ``serializer`` service will be available in the container
89-
and will be loaded with four :ref:`encoders <component-serializer-encoders>`
90-
(:class:`Symfony\\Component\\Serializer\\Encoder\\JsonEncoder`,
91-
:class:`Symfony\\Component\\Serializer\\Encoder\\XmlEncoder`,
92-
:class:`Symfony\\Component\\Serializer\\Encoder\\YamlEncoder`, and
93-
:class:`Symfony\\Component\\Serializer\\Encoder\\CsvEncoder`) and the
94-
:ref:`ObjectNormalizer normalizer <component-serializer-normalizers>`.
95-
96-
You can load normalizers and/or encoders by tagging them as
88+
Once enabled, the ``serializer`` service will be available in the container.
89+
It comes with a set of useful :ref:`encoders <component-serializer-encoders>`
90+
and :ref:`normalizers <component-serializer-normalizers>`.
91+
92+
Encoders supporting the following formats are enabled:
93+
94+
* JSON: :class:`Symfony\\Component\\Serializer\\Encoder\\JsonEncoder`
95+
* XML: :class:`Symfony\\Component\\Serializer\\Encoder\\XmlEncoder`
96+
97+
As well as the following normalizers:
98+
99+
* :class:`Symfony\\Component\\Serializer\\Normalizer\\ObjectNormalizer` to
100+
handle typical data objects
101+
* :class:`Symfony\\Component\\Serializer\\Normalizer\\DateTimeNormalizer` for
102+
objects implementing the :class:`DateTimeInterface` interface
103+
* :class:`Symfony\\Component\\Serializer\\Normalizer\\DataUriNormalizer` to
104+
transform :class:`SplFileInfo` objects in `Data URIs`_
105+
* :class:`Symfony\\Component\\Serializer\\Normalizer\\JsonSerializableNormalizer`
106+
to deal with objects implementing the :class:`JsonSerializable` interface
107+
* :class:`Symfony\\Component\\Serializer\\Normalizer\\ArrayDenormalizer` to
108+
denormalize arrays of objects using a format like `MyObject[]` (note the `[]` suffix)
109+
110+
Custom normalizers and/or encoders can also be loaded by tagging them as
97111
:ref:`serializer.normalizer <reference-dic-tags-serializer-normalizer>` and
98112
:ref:`serializer.encoder <reference-dic-tags-serializer-encoder>`. It's also
99113
possible to set the priority of the tag in order to decide the matching order.
100114

101115
Here is an example on how to load the
102-
:class:`Symfony\\Component\\Serializer\\Normalizer\\GetSetMethodNormalizer`:
116+
:class:`Symfony\\Component\\Serializer\\Normalizer\\GetSetMethodNormalizer`, a
117+
faster alternative to the `ObjectNormalizer` when data objects always use
118+
getters and setters:
103119

104120
.. configuration-block::
105121

@@ -310,3 +326,4 @@ take a look at how this bundle works.
310326
.. _`ApiPlatform`: https://github.com/api-platform/core
311327
.. _`JSON-LD`: http://json-ld.org
312328
.. _`Hydra Core Vocabulary`: http://hydra-cg.com
329+
.. _`Data URIs`: https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs

0 commit comments

Comments
 (0)