@@ -63,48 +63,19 @@ a service and :doc:`tagged </service_container/tags>` with ``serializer.normaliz
63
63
If you're using the :ref: `default services.yaml configuration <service-container-services-load-example >`,
64
64
this is done automatically!
65
65
66
- Performance
67
- -----------
66
+ Performance of Normalizers/Denormalizers
67
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
68
68
69
69
To figure which normalizer (or denormalizer) must be used to handle an object,
70
70
the :class: `Symfony\\ Component\\ Serializer\\ Serializer ` class will call the
71
71
:method: `Symfony\\ Component\\ Serializer\\ Normalizer\\ NormalizerInterface::supportsNormalization `
72
72
(or :method: `Symfony\\ Component\\ Serializer\\ Normalizer\\ DenormalizerInterface::supportsDenormalization `)
73
73
of all registered normalizers (or denormalizers) in a loop.
74
74
75
- The result of these methods can vary depending on the object to serialize, the
76
- format and the context. That's why the result **is not cached ** by default and
77
- can result in a significant performance bottleneck.
78
-
79
- However, most normalizers (and denormalizers) always return the same result when
80
- the object's type and the format are the same, so the result can be cached. To
81
- do so, make those normalizers (and denormalizers) implement the
82
- :class: `Symfony\\ Component\\ Serializer\\ Normalizer\\ CacheableSupportsMethodInterface `
83
- and return ``true `` when
84
- :method: `Symfony\\ Component\\ Serializer\\ Normalizer\\ CacheableSupportsMethodInterface::hasCacheableSupportsMethod `
85
- is called.
86
-
87
- .. note ::
88
-
89
- All built-in :ref: `normalizers and denormalizers <component-serializer-normalizers >`
90
- as well the ones included in `API Platform `_ natively implement this interface.
91
-
92
- .. deprecated :: 6.3
93
-
94
- The :class: `Symfony\\ Component\\ Serializer\\ Normalizer\\ CacheableSupportsMethodInterface `
95
- interface is deprecated since Symfony 6.3. You should implement the
96
- ``getSupportedTypes() `` method instead, as shown in the section below.
97
-
98
- Improving Performance of Normalizers/Denormalizers
99
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
100
-
101
- .. versionadded :: 6.3
102
-
103
- The ``getSupportedTypes() `` method was introduced in Symfony 6.3.
104
-
105
- Both :class: `Symfony\\ Component\\ Serializer\\ Normalizer\\ NormalizerInterface `
75
+ Additionally, both
76
+ :class: `Symfony\\ Component\\ Serializer\\ Normalizer\\ NormalizerInterface `
106
77
and :class: `Symfony\\ Component\\ Serializer\\ Normalizer\\ DenormalizerInterface `
107
- contain a new method ``getSupportedTypes() ``. This method allows normalizers or
78
+ contain the ``getSupportedTypes() `` method . This method allows normalizers or
108
79
denormalizers to declare the type of objects they can handle, and whether they
109
80
are cacheable. With this info, even if the ``supports*() `` call is not cacheable,
110
81
the Serializer can skip a ton of method calls to ``supports*() `` improving
@@ -148,5 +119,3 @@ Here is an example of how to use the ``getSupportedTypes()`` method::
148
119
149
120
Note that ``supports*() `` method implementations should not assume that
150
121
``getSupportedTypes() `` has been called before.
151
-
152
- .. _`API Platform` : https://api-platform.com
0 commit comments