In Drupal 9.2.6 I have a caching issue.

The code I am using is the following.

$returnValues = [
  'value' => 'test',
  'time' => time(),

$response = new ResourceResponse($returnValues, 200, []);
$disable_cache = new CacheableMetadata();
return $response;

This leads to this error.

TypeError: Argument 1 passed to Symfony\Component\Serializer\Encoder\ChainEncoder::getEncoder() must be of the type string, null given, called in /webspace/public/vendor/symfony/serializer/Encoder/ChainEncoder.php on line 49 in Symfony\Component\Serializer\Encoder\ChainEncoder->getEncoder() (Zeile 80 in /webspace/public/vendor/symfony/serializer/Encoder/ChainEncoder.php)

This is also doesn't work.

$response = new ResourceResponse($returnValues);
return $response;

What's wrong?


Use Drupal\rest\ModifiedResourceResponse instead of ResourceResponse, then it won't be cached.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.