Skip to content

Commit 7bd75b3

Browse files
committed
Merge branch '5.1' into 5.2
* 5.1: [Serializer] move note on Custom Normalizer page about cacheable performance
2 parents ffbd30e + cbf2d22 commit 7bd75b3

File tree

2 files changed

+29
-26
lines changed

2 files changed

+29
-26
lines changed

components/serializer.rst

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,32 +1557,6 @@ Once configured, the serializer uses the mapping to pick the correct class::
15571557
$repository = $serializer->deserialize($serialized, CodeRepository::class, 'json');
15581558
// instanceof GitHubCodeRepository
15591559

1560-
Performance
1561-
-----------
1562-
1563-
To figure which normalizer (or denormalizer) must be used to handle an object,
1564-
the :class:`Symfony\\Component\\Serializer\\Serializer` class will call the
1565-
:method:`Symfony\\Component\\Serializer\\Normalizer\\NormalizerInterface::supportsNormalization`
1566-
(or :method:`Symfony\\Component\\Serializer\\Normalizer\\DenormalizerInterface::supportsDenormalization`)
1567-
of all registered normalizers (or denormalizers) in a loop.
1568-
1569-
The result of these methods can vary depending on the object to serialize, the
1570-
format and the context. That's why the result **is not cached** by default and
1571-
can result in a significant performance bottleneck.
1572-
1573-
However, most normalizers (and denormalizers) always return the same result when
1574-
the object's type and the format are the same, so the result can be cached. To
1575-
do so, make those normalizers (and denormalizers) implement the
1576-
:class:`Symfony\\Component\\Serializer\\Normalizer\\CacheableSupportsMethodInterface`
1577-
and return ``true`` when
1578-
:method:`Symfony\\Component\\Serializer\\Normalizer\\CacheableSupportsMethodInterface::hasCacheableSupportsMethod`
1579-
is called.
1580-
1581-
.. note::
1582-
1583-
All built-in :ref:`normalizers and denormalizers <component-serializer-normalizers>`
1584-
as well the ones included in `API Platform`_ natively implement this interface.
1585-
15861560
Learn more
15871561
----------
15881562

serializer/custom_normalizer.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,32 @@ Before using this normalizer in a Symfony application it must be registered as
6161
a service and :doc:`tagged </service_container/tags>` with ``serializer.normalizer``.
6262
If you're using the :ref:`default services.yaml configuration <service-container-services-load-example>`,
6363
this is done automatically!
64+
65+
Performance
66+
-----------
67+
68+
To figure which normalizer (or denormalizer) must be used to handle an object,
69+
the :class:`Symfony\\Component\\Serializer\\Serializer` class will call the
70+
:method:`Symfony\\Component\\Serializer\\Normalizer\\NormalizerInterface::supportsNormalization`
71+
(or :method:`Symfony\\Component\\Serializer\\Normalizer\\DenormalizerInterface::supportsDenormalization`)
72+
of all registered normalizers (or denormalizers) in a loop.
73+
74+
The result of these methods can vary depending on the object to serialize, the
75+
format and the context. That's why the result **is not cached** by default and
76+
can result in a significant performance bottleneck.
77+
78+
However, most normalizers (and denormalizers) always return the same result when
79+
the object's type and the format are the same, so the result can be cached. To
80+
do so, make those normalizers (and denormalizers) implement the
81+
:class:`Symfony\\Component\\Serializer\\Normalizer\\CacheableSupportsMethodInterface`
82+
and return ``true`` when
83+
:method:`Symfony\\Component\\Serializer\\Normalizer\\CacheableSupportsMethodInterface::hasCacheableSupportsMethod`
84+
is called.
85+
86+
.. note::
87+
88+
All built-in :ref:`normalizers and denormalizers <component-serializer-normalizers>`
89+
as well the ones included in `API Platform`_ natively implement this interface.
90+
91+
.. _`API Platform`: https://api-platform.com
92+

0 commit comments

Comments
 (0)