فهرست منبع

added a sanity check

Johannes M. Schmitt 13 سال پیش
والد
کامیت
356c35d3c7
1فایلهای تغییر یافته به همراه11 افزوده شده و 1 حذف شده
  1. 11 1
      Serializer/GraphNavigator.php

+ 11 - 1
Serializer/GraphNavigator.php

@@ -95,8 +95,18 @@ final class GraphNavigator
      */
     public function accept($data, array $type = null, VisitorInterface $visitor)
     {
-        // determine type if not given
+        // If the type was not given, we infer the most specific type from the
+        // input data in serialization mode.
         if (null === $type) {
+            if (self::DIRECTION_DESERIALIZATION === $this->direction) {
+                $msg = 'The type must be given for all properties when deserializing.';
+                if (null !== $path = $this->getCurrentPath()) {
+                    $msg .= ' Path: '.$path;
+                }
+
+                throw new \RuntimeException($msg);
+            }
+
             if (null === $data) {
                 return null;
             }