Pārlūkot izejas kodu

Erroneous data format for unserializing #430

Milos Tomic 10 gadi atpakaļ
vecāks
revīzija
a9e1ee89be

+ 17 - 1
src/JMS/Serializer/Construction/UnserializeObjectConstructor.php

@@ -18,14 +18,30 @@
 
 namespace JMS\Serializer\Construction;
 
+use Doctrine\Instantiator\Instantiator;
 use JMS\Serializer\VisitorInterface;
 use JMS\Serializer\Metadata\ClassMetadata;
 use JMS\Serializer\DeserializationContext;
 
 class UnserializeObjectConstructor implements ObjectConstructorInterface
 {
+    /** @var Instantiator  */
+    private $instantiator;
+
     public function construct(VisitorInterface $visitor, ClassMetadata $metadata, $data, array $type, DeserializationContext $context)
     {
-        return unserialize(sprintf('O:%d:"%s":0:{}', strlen($metadata->name), $metadata->name));
+        return $this->getInstantiator()->instantiate($metadata->name);
+    }
+
+    /**
+     * @return Instantiator
+     */
+    private function getInstantiator()
+    {
+        if (null == $this->instantiator) {
+            $this->instantiator = new Instantiator();
+        }
+
+        return $this->instantiator;
     }
 }