diff --git a/core/modules/serialization/src/Normalizer/NormalizerBase.php b/core/modules/serialization/src/Normalizer/NormalizerBase.php
index 958aaf2f4c..c7cea8ac7d 100644
--- a/core/modules/serialization/src/Normalizer/NormalizerBase.php
+++ b/core/modules/serialization/src/Normalizer/NormalizerBase.php
@@ -92,8 +92,10 @@ protected function checkFormat($format = NULL) {
    *   The data that might have cacheability information.
    */
   protected function addCacheableDependency(array $context, $data) {
-    if ($data instanceof CacheableDependencyInterface && isset($context[ResourceResponseSubscriber::SERIALIZATION_CONTEXT_CACHEABILITY])) {
-      $context[ResourceResponseSubscriber::SERIALIZATION_CONTEXT_CACHEABILITY]->addCacheableDependency($data);
+    // Using \Drupal\rest\EventSubscriber\ResourceResponseSubscriber::SERIALIZATION_CONTEXT_CACHEABILITY
+    // would be ideal, but there should be no dependency to the rest module.
+    if ($data instanceof CacheableDependencyInterface && isset($context['cacheability'])) {
+      $context['cacheability']->addCacheableDependency($data);
     }
   }
 
