From 0b0d0375c36a7ca7f4d7549491d4c703b08309ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Tue, 14 Feb 2017 16:44:15 +0100 Subject: [PATCH 1/2] [Serializer] Add new default normalizers --- serializer.rst | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/serializer.rst b/serializer.rst index 7fef2106f0b..858b1176016 100644 --- a/serializer.rst +++ b/serializer.rst @@ -82,19 +82,30 @@ 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 `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) + +You can also load custom normalizers and/or encoders by tagging them 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` +if your data objects always use getters and setters: .. configuration-block:: @@ -283,3 +294,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 From f9092653ea90e6d42789b0d472de83dfea00a6d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Tue, 5 Sep 2017 13:35:06 +0200 Subject: [PATCH 2/2] Fix comments --- serializer.rst | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/serializer.rst b/serializer.rst index 858b1176016..3a4170971ae 100644 --- a/serializer.rst +++ b/serializer.rst @@ -82,8 +82,9 @@ 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. It comes with a set of useful :ref:`encoders ` -and `normalizers `. +Once enabled, the ``serializer`` service will be available in the container. +It comes with a set of useful :ref:`encoders ` +and :ref:`normalizers `. Encoders supporting the following formats are enabled: @@ -92,20 +93,26 @@ Encoders supporting the following formats are enabled: 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) - -You can also load custom normalizers and/or encoders by tagging them as +* :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`, a faster alternative to the `ObjectNormalizer` -if your data objects always use getters and setters: +:class:`Symfony\\Component\\Serializer\\Normalizer\\GetSetMethodNormalizer`, a +faster alternative to the `ObjectNormalizer` when data objects always use +getters and setters: .. configuration-block::