diff --git a/core/modules/rest/src/RequestHandler.php b/core/modules/rest/src/RequestHandler.php
index 0ddfdd7..0f1493b 100644
--- a/core/modules/rest/src/RequestHandler.php
+++ b/core/modules/rest/src/RequestHandler.php
@@ -106,6 +106,10 @@ public function handle(RouteMatchInterface $route_match, Request $request, Route
 
     // Serialize the outgoing data for the response, if available.
     $data = $response->getResponseData();
+    // Treat \stdClass as an array.
+    if ($data instanceof \stdClass) {
+      $data = (array)$data;
+    }
     if ($data != NULL) {
       $output = $serializer->serialize($data, $format);
       $response->setContent($output);
