Skip to content

Commit 17dec97

Browse files
committed
Merge branch '4.4' into 5.3
* 4.4: Add the redirection for the removed page Remove redundant normalizers document Fix invalid statement about normalizers
2 parents 6dc1ce0 + 7b083f6 commit 17dec97

File tree

4 files changed

+57
-79
lines changed

4 files changed

+57
-79
lines changed

_build/redirection_map

+1
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,7 @@
516516
/testing/functional_tests_assertions /testing#testing-application-assertions
517517
/components https://symfony.com/components
518518
/components/index https://symfony.com/components
519+
/serializer/normalizers /components/serializer#normalizers
519520
/logging/monolog_regex_based_excludes /logging/monolog_exclude_http_codes
520521
/security/named_encoders /security/named_hashers
521522
/security/experimental_authenticators /security

components/serializer.rst

+56-6
Original file line numberDiff line numberDiff line change
@@ -789,13 +789,13 @@ When serializing, you can set a callback to format a specific object property::
789789
Normalizers
790790
-----------
791791

792-
Normalizers turn **object** into **array** and vice versa. They implement
793-
:class:`Symfony\\Component\\Serializer\\Normalizer\\NormalizableInterface`
794-
for normalize (object to array) and
795-
:class:`Symfony\\Component\\Serializer\\Normalizer\\DenormalizableInterface` for denormalize
796-
(array to object).
792+
Normalizers turn **objects** into **arrays** and vice versa. They implement
793+
:class:`Symfony\\Component\\Serializer\\Normalizer\\NormalizerInterface` for
794+
normalizing (object to array) and
795+
:class:`Symfony\\Component\\Serializer\\Normalizer\\DenormalizerInterface` for
796+
denormalizing (array to object).
797797

798-
You can add new normalizers to a Serializer instance by using its first constructor argument::
798+
Normalizers are enabled in the serializer passing them as its first argument::
799799

800800
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
801801
use Symfony\Component\Serializer\Serializer;
@@ -908,6 +908,56 @@ The Serializer component provides several built-in normalizers:
908908

909909
The ``UidNormalizer`` normalization formats were introduced in Symfony 5.3.
910910

911+
Certain normalizers are enabled by default when using the Serializer component
912+
in a Symfony application, additional ones can be enabled by tagging them with
913+
:ref:`serializer.normalizer <reference-dic-tags-serializer-normalizer>`.
914+
915+
Here is an example of how to enable the built-in
916+
:class:`Symfony\\Component\\Serializer\\Normalizer\\GetSetMethodNormalizer`, a
917+
faster alternative to the
918+
:class:`Symfony\\Component\\Serializer\\Normalizer\\ObjectNormalizer`:
919+
920+
.. configuration-block::
921+
922+
.. code-block:: yaml
923+
924+
# config/services.yaml
925+
services:
926+
get_set_method_normalizer:
927+
class: Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer
928+
tags: [serializer.normalizer]
929+
930+
.. code-block:: xml
931+
932+
<!-- config/services.xml -->
933+
<?xml version="1.0" encoding="UTF-8" ?>
934+
<container xmlns="http://symfony.com/schema/dic/services"
935+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
936+
xsi:schemaLocation="http://symfony.com/schema/dic/services
937+
https://symfony.com/schema/dic/services/services-1.0.xsd">
938+
939+
<services>
940+
<service id="get_set_method_normalizer" class="Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer">
941+
<tag name="serializer.normalizer"/>
942+
</service>
943+
</services>
944+
</container>
945+
946+
.. code-block:: php
947+
948+
// config/services.php
949+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
950+
951+
use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer;
952+
953+
return function(ContainerConfigurator $configurator) {
954+
$services = $configurator->services();
955+
956+
$services->set('get_set_method_normalizer', GetSetMethodNormalizer::class)
957+
->tag('serializer.normalizer')
958+
;
959+
};
960+
911961
.. _component-serializer-encoders:
912962

913963
Encoders

serializer.rst

-48
Original file line numberDiff line numberDiff line change
@@ -93,53 +93,6 @@ possible to set the priority of the tag in order to decide the matching order.
9393
``DateTime`` or ``DateTimeImmutable`` classes to avoid excessive memory
9494
usage and exposing internal details.
9595

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

14598
Using Serialization Groups Annotations
@@ -282,7 +235,6 @@ take a look at how this bundle works.
282235
.. toctree::
283236
:maxdepth: 1
284237

285-
serializer/normalizers
286238
serializer/custom_encoders
287239
serializer/custom_normalizer
288240

serializer/normalizers.rst

-25
This file was deleted.

0 commit comments

Comments
 (0)