瀏覽代碼

added special handling for persistent collections

Johannes Schmitt 12 年之前
父節點
當前提交
b1fe04f7c9
共有 1 個文件被更改,包括 7 次插入0 次删除
  1. 7 0
      Serializer/EventDispatcher/Subscriber/DoctrineProxySubscriber.php

+ 7 - 0
Serializer/EventDispatcher/Subscriber/DoctrineProxySubscriber.php

@@ -2,6 +2,7 @@
 
 namespace JMS\SerializerBundle\Serializer\EventDispatcher\Subscriber;
 
+use Doctrine\ORM\PersistentCollection;
 use Doctrine\Common\Persistence\Proxy;
 use Doctrine\ORM\Proxy\Proxy as ORMProxy;
 use JMS\SerializerBundle\Serializer\EventDispatcher\PreSerializeEvent;
@@ -13,6 +14,12 @@ class DoctrineProxySubscriber implements EventSubscriberInterface
     {
         $object = $event->getObject();
 
+        if ($object instanceof PersistentCollection) {
+            $event->setType('ArrayCollection');
+
+            return;
+        }
+
         if ( ! $object instanceof Proxy && ! $object instanceof ORMProxy) {
             return;
         }