@@ -1295,6 +1295,33 @@ can use this simpler configuration:
1295
1295
</class >
1296
1296
</serializer >
1297
1297
1298
+ Performance
1299
+ -----------
1300
+
1301
+ To figure which normalizer (or denormalizer) must be used to handle an object,
1302
+ the :class: `Symfony\\ Component\\ Serializer\\ Serializer ` class will call the
1303
+ :method: `Symfony\C omponent\S erializer\N ormalizer\N ormalizerInterface::supportsNormalization `
1304
+ (or :method: `Symfony\C omponent\S erializer\N ormalizer\D enormalizerInterface::supportsDenormalization `)
1305
+ of all registered normalizers (or denormalizers) in a loop.
1306
+
1307
+ The result of these methods can vary depending of the value of the object to serialize, of the format to
1308
+ use, and of the context. Consequently, **it is not cached ** by default.
1309
+
1310
+ Because they are called recursively, these methods are usually a huge performance bottleneck. Moreover, most
1311
+ normalizers (and denormalizers) always return the same result when the object's type, and the format are
1312
+ the same.
1313
+
1314
+ To hint the serializer that it's safe to cache the result of these methods (and then dramatically improve the
1315
+ overall performance), such normalizers (and denormalizers) should implement the
1316
+ :class: `Symfony\C omponent\S erializer\N ormalizer\C acheableSupportsMethodInterface ` and return ``true `` when
1317
+ :method: `Symfony\C omponent\S erializer\N ormalizer\C acheableSupportsMethodInterface::hasCacheableSupportsMethod `
1318
+ is called.
1319
+
1320
+ .. note ::
1321
+
1322
+ Built-in :ref: `normalizers and denormalizers <component-serializer-normalizers >`, as well the ones
1323
+ included in `API Platform `_ natively implement this interface.
1324
+
1298
1325
Learn more
1299
1326
----------
1300
1327
@@ -1304,6 +1331,11 @@ Learn more
1304
1331
1305
1332
/serializer
1306
1333
1334
+ .. seealso ::
1335
+
1336
+ Normalizers for the Symfony Serializer Component supporting popular web API formats
1337
+ (JSON-LD, GraphQL, HAL and JSONAPI) are available as part of the `API Platform `_ project.
1338
+
1307
1339
.. seealso ::
1308
1340
1309
1341
A popular alternative to the Symfony Serializer Component is the third-party
@@ -1320,3 +1352,4 @@ Learn more
1320
1352
.. _CSV : https://tools.ietf.org/html/rfc4180
1321
1353
.. _`RFC 7807` : https://tools.ietf.org/html/rfc7807
1322
1354
.. _`Value Objects` : https://en.wikipedia.org/wiki/Value_object
1355
+ .. _`API Platform` : https://api-platform.com
0 commit comments