Skip to content

Commit 7b083f6

Browse files
committed
minor #16371 [Serializer] Fix invalid statement about normalizers (HypeMC)
This PR was merged into the 4.4 branch. Discussion ---------- [Serializer] Fix invalid statement about normalizers Not all normalizers are enabled by default, e.g. the `GetSetMethodNormalizer` isn't. I've moved the example of how to enable additional normalizers to `components/serializer.rst`, `serializer.rst` already has a link to it on line 70. Commits ------- 131bc20 Fix invalid statement about normalizers
2 parents e57adef + 131bc20 commit 7b083f6

File tree

2 files changed

+49
-49
lines changed

2 files changed

+49
-49
lines changed

components/serializer.rst

+49-2
Original file line numberDiff line numberDiff line change
@@ -801,8 +801,55 @@ The Serializer component provides several built-in normalizers:
801801
You can also create your own Normalizer to use another structure. Read more at
802802
:doc:`/serializer/custom_normalizer`.
803803

804-
All these normalizers are enabled by default when using the Serializer component
805-
in a Symfony application.
804+
Certain normalizers are enabled by default when using the Serializer component
805+
in a Symfony application, additional ones can be enabled by tagging them with
806+
:ref:`serializer.normalizer <reference-dic-tags-serializer-normalizer>`.
807+
808+
Here is an example of how to enable the built-in
809+
:class:`Symfony\\Component\\Serializer\\Normalizer\\GetSetMethodNormalizer`, a
810+
faster alternative to the
811+
:class:`Symfony\\Component\\Serializer\\Normalizer\\ObjectNormalizer`:
812+
813+
.. configuration-block::
814+
815+
.. code-block:: yaml
816+
817+
# config/services.yaml
818+
services:
819+
get_set_method_normalizer:
820+
class: Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer
821+
tags: [serializer.normalizer]
822+
823+
.. code-block:: xml
824+
825+
<!-- config/services.xml -->
826+
<?xml version="1.0" encoding="UTF-8" ?>
827+
<container xmlns="http://symfony.com/schema/dic/services"
828+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
829+
xsi:schemaLocation="http://symfony.com/schema/dic/services
830+
https://symfony.com/schema/dic/services/services-1.0.xsd">
831+
832+
<services>
833+
<service id="get_set_method_normalizer" class="Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer">
834+
<tag name="serializer.normalizer"/>
835+
</service>
836+
</services>
837+
</container>
838+
839+
.. code-block:: php
840+
841+
// config/services.php
842+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
843+
844+
use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer;
845+
846+
return function(ContainerConfigurator $configurator) {
847+
$services = $configurator->services();
848+
849+
$services->set('get_set_method_normalizer', GetSetMethodNormalizer::class)
850+
->tag('serializer.normalizer')
851+
;
852+
};
806853
807854
.. _component-serializer-encoders:
808855

serializer.rst

-47
Original file line numberDiff line numberDiff line change
@@ -79,53 +79,6 @@ possible to set the priority of the tag in order to decide the matching order.
7979
``DateTime`` or ``DateTimeImmutable`` classes to avoid excessive memory
8080
usage and exposing internal details.
8181

82-
Here is an example on how to load the built-in
83-
:class:`Symfony\\Component\\Serializer\\Normalizer\\GetSetMethodNormalizer`, a
84-
faster alternative to the `ObjectNormalizer` when data objects always use
85-
getters (``getXxx()``), issers (``isXxx()``) or hassers (``hasXxx()``) to read
86-
properties and setters (``setXxx()``) to change properties:
87-
88-
.. configuration-block::
89-
90-
.. code-block:: yaml
91-
92-
# config/services.yaml
93-
services:
94-
get_set_method_normalizer:
95-
class: Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer
96-
tags: [serializer.normalizer]
97-
98-
.. code-block:: xml
99-
100-
<!-- config/services.xml -->
101-
<?xml version="1.0" encoding="UTF-8" ?>
102-
<container xmlns="http://symfony.com/schema/dic/services"
103-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
104-
xsi:schemaLocation="http://symfony.com/schema/dic/services
105-
https://symfony.com/schema/dic/services/services-1.0.xsd">
106-
107-
<services>
108-
<service id="get_set_method_normalizer" class="Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer">
109-
<tag name="serializer.normalizer"/>
110-
</service>
111-
</services>
112-
</container>
113-
114-
.. code-block:: php
115-
116-
// config/services.php
117-
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
118-
119-
use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer;
120-
121-
return function(ContainerConfigurator $configurator) {
122-
$services = $configurator->services();
123-
124-
$services->set('get_set_method_normalizer', GetSetMethodNormalizer::class)
125-
->tag('serializer.normalizer')
126-
;
127-
};
128-
12982
.. _serializer-using-serialization-groups-annotations:
13083

13184
Using Serialization Groups Annotations

0 commit comments

Comments
 (0)