diff --git a/serializer.rst b/serializer.rst index 7fef2106f0b..3a4170971ae 100644 --- a/serializer.rst +++ b/serializer.rst @@ -82,19 +82,37 @@ you need it or it can be used in a controller like the following:: Adding Normalizers and Encoders ------------------------------- -Once enabled, the ``serializer`` service will be available in the container -and will be loaded with two :ref:`encoders ` -(:class:`Symfony\\Component\\Serializer\\Encoder\\JsonEncoder` and -:class:`Symfony\\Component\\Serializer\\Encoder\\XmlEncoder`) and the -:ref:`ObjectNormalizer normalizer `. +Once enabled, the ``serializer`` service will be available in the container. +It comes with a set of useful :ref:`encoders ` +and :ref:`normalizers `. -You can load normalizers and/or encoders by tagging them as +Encoders supporting the following formats are enabled: + +* JSON: :class:`Symfony\\Component\\Serializer\\Encoder\\JsonEncoder` +* XML: :class:`Symfony\\Component\\Serializer\\Encoder\\XmlEncoder` + +As well as the following normalizers: + +* :class:`Symfony\\Component\\Serializer\\Normalizer\\ObjectNormalizer` to + handle typical data objects +* :class:`Symfony\\Component\\Serializer\\Normalizer\\DateTimeNormalizer` for + objects implementing the :class:`DateTimeInterface` interface +* :class:`Symfony\\Component\\Serializer\\Normalizer\\DataUriNormalizer` to + transform :class:`SplFileInfo` objects in `Data URIs`_ +* :class:`Symfony\\Component\\Serializer\\Normalizer\\JsonSerializableNormalizer` + to deal with object implementing the :class:`JsonSerializable` interface +* :class:`Symfony\\Component\\Serializer\\Normalizer\\ArrayDenormalizer` to + denormalize arrays of objects using a format like `MyObject[]` (note the `[]` suffix) + +Custom normalizers and/or encoders can also be loaded by tagging as :ref:`serializer.normalizer ` and :ref:`serializer.encoder `. It's also possible to set the priority of the tag in order to decide the matching order. Here is an example on how to load the -:class:`Symfony\\Component\\Serializer\\Normalizer\\GetSetMethodNormalizer`: +:class:`Symfony\\Component\\Serializer\\Normalizer\\GetSetMethodNormalizer`, a +faster alternative to the `ObjectNormalizer` when data objects always use +getters and setters: .. configuration-block:: @@ -283,3 +301,4 @@ take a look at how this bundle works. .. _`ApiPlatform`: https://github.com/api-platform/core .. _`JSON-LD`: http://json-ld.org .. _`Hydra Core Vocabulary`: http://hydra-cg.com +.. _`Data URIs`: https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs