فهرست منبع

Fix in GraphNavigator for serialization of polymorphic objects

David Simon 11 سال پیش
والد
کامیت
cd90daaa17
1فایلهای تغییر یافته به همراه8 افزوده شده و 0 حذف شده
  1. 8 0
      src/JMS/Serializer/GraphNavigator.php

+ 8 - 0
src/JMS/Serializer/GraphNavigator.php

@@ -145,6 +145,14 @@ final class GraphNavigator
                         }
                         $context->startVisiting($data);
                     }
+
+                    // If we're serializing a polymorphic type, then we'll be interested in the
+                    // metadata for the actual type of the object, not the base class.
+                    if (class_exists($type['name'], false)) {
+                        if (is_subclass_of($data, $type['name'], false)) {
+                            $type = array('name' => get_class($data), 'params' => array());
+                        }
+                    }
                 } elseif ($context instanceof DeserializationContext) {
                     $context->increaseDepth();
                 }