Sfoglia il codice sorgente

Fix in GraphNavigator for serialization of polymorphic objects

David Simon 11 anni fa
parent
commit
cd90daaa17
1 ha cambiato i file con 8 aggiunte e 0 eliminazioni
  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();
                 }