diff --git a/core/lib/Drupal/Core/Menu/MenuTreeParameters.php b/core/lib/Drupal/Core/Menu/MenuTreeParameters.php
index f7c61488018e8767bbd49dd251fd9f0ce503ae74..1711297ec2c4289e44bf6318edfcfe89998a9b47 100644
--- a/core/lib/Drupal/Core/Menu/MenuTreeParameters.php
+++ b/core/lib/Drupal/Core/Menu/MenuTreeParameters.php
@@ -212,6 +212,21 @@ public function excludeRoot() {
    * {@inheritdoc}
    */
   public function serialize() {
+    return serialize($this->__serialize());
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function unserialize($serialized) {
+    $this->__unserialize(unserialize($serialized));
+    return $this;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function __serialize(): array {
     // Enforce type consistency for all the internal properties of this object.
     $this->root = (string) $this->root;
     $this->minDepth = $this->minDepth !== NULL ? (int) $this->minDepth : NULL;
@@ -222,25 +237,23 @@ public function serialize() {
     sort($this->expandedParents);
     asort($this->conditions);
 
-    return serialize([
+    return [
       'root' => $this->root,
       'minDepth' => $this->minDepth,
       'maxDepth' => $this->maxDepth,
       'expandedParents' => $this->expandedParents,
       'activeTrail' => $this->activeTrail,
       'conditions' => $this->conditions,
-    ]);
+    ];
   }
 
   /**
    * {@inheritdoc}
    */
-  public function unserialize($serialized) {
-    foreach (unserialize($serialized) as $key => $value) {
+  public function __unserialize(array $data): void {
+    foreach ($data as $key => $value) {
       $this->{$key} = $value;
     }
-
-    return $this;
   }
 
 }