From 131bc2043886d6745e0ed52c3d6a996a25c08195 Mon Sep 17 00:00:00 2001 From: HypeMC Date: Wed, 5 Jan 2022 10:16:20 +0100 Subject: [PATCH] Fix invalid statement about normalizers - not all normalizers are enabled by default --- components/serializer.rst | 51 +++++++++++++++++++++++++++++++++++++-- serializer.rst | 47 ------------------------------------ 2 files changed, 49 insertions(+), 49 deletions(-) diff --git a/components/serializer.rst b/components/serializer.rst index 2e43ac571f5..db38513e36a 100644 --- a/components/serializer.rst +++ b/components/serializer.rst @@ -801,8 +801,55 @@ The Serializer component provides several built-in normalizers: You can also create your own Normalizer to use another structure. Read more at :doc:`/serializer/custom_normalizer`. -All these normalizers are enabled by default when using the Serializer component -in a Symfony application. +Certain normalizers are enabled by default when using the Serializer component +in a Symfony application, additional ones can be enabled by tagging them with +:ref:`serializer.normalizer `. + +Here is an example of how to enable the built-in +:class:`Symfony\\Component\\Serializer\\Normalizer\\GetSetMethodNormalizer`, a +faster alternative to the +:class:`Symfony\\Component\\Serializer\\Normalizer\\ObjectNormalizer`: + +.. configuration-block:: + + .. code-block:: yaml + + # config/services.yaml + services: + get_set_method_normalizer: + class: Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer + tags: [serializer.normalizer] + + .. code-block:: xml + + + + + + + + + + + + + .. code-block:: php + + // config/services.php + namespace Symfony\Component\DependencyInjection\Loader\Configurator; + + use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer; + + return function(ContainerConfigurator $configurator) { + $services = $configurator->services(); + + $services->set('get_set_method_normalizer', GetSetMethodNormalizer::class) + ->tag('serializer.normalizer') + ; + }; .. _component-serializer-encoders: diff --git a/serializer.rst b/serializer.rst index 4216d619c15..3fecc7bec8e 100644 --- a/serializer.rst +++ b/serializer.rst @@ -79,53 +79,6 @@ possible to set the priority of the tag in order to decide the matching order. ``DateTime`` or ``DateTimeImmutable`` classes to avoid excessive memory usage and exposing internal details. -Here is an example on how to load the built-in -:class:`Symfony\\Component\\Serializer\\Normalizer\\GetSetMethodNormalizer`, a -faster alternative to the `ObjectNormalizer` when data objects always use -getters (``getXxx()``), issers (``isXxx()``) or hassers (``hasXxx()``) to read -properties and setters (``setXxx()``) to change properties: - -.. configuration-block:: - - .. code-block:: yaml - - # config/services.yaml - services: - get_set_method_normalizer: - class: Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer - tags: [serializer.normalizer] - - .. code-block:: xml - - - - - - - - - - - - - .. code-block:: php - - // config/services.php - namespace Symfony\Component\DependencyInjection\Loader\Configurator; - - use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer; - - return function(ContainerConfigurator $configurator) { - $services = $configurator->services(); - - $services->set('get_set_method_normalizer', GetSetMethodNormalizer::class) - ->tag('serializer.normalizer') - ; - }; - .. _serializer-using-serialization-groups-annotations: Using Serialization Groups Annotations