Skip to content

Commit 756d0b5

Browse files
committed
Merge branch '5.2' into 5.x
* 5.2: [Serializer] move note on Custom Normalizer page about cacheable performance
2 parents 7004324 + 7bd75b3 commit 756d0b5

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
@@ -1561,32 +1561,6 @@ Once configured, the serializer uses the mapping to pick the correct class::
15611561
$repository = $serializer->deserialize($serialized, CodeRepository::class, 'json');
15621562
// instanceof GitHubCodeRepository
15631563

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

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)