diff --git a/src/GraphNavigator/DeserializationGraphNavigator.php b/src/GraphNavigator/DeserializationGraphNavigator.php index 7c9dbab5a..d47f49001 100644 --- a/src/GraphNavigator/DeserializationGraphNavigator.php +++ b/src/GraphNavigator/DeserializationGraphNavigator.php @@ -123,9 +123,9 @@ public function accept($data, ?array $type = null) // Sometimes data can convey null but is not of a null type. // Visitors can have the power to add this custom null evaluation // If null is explicitly allowed we should skip this - if (false === $this->shouldDeserializeNull - && $this->visitor instanceof NullAwareVisitorInterface + if ($this->visitor instanceof NullAwareVisitorInterface && true === $this->visitor->isNull($data) + && (!empty($type['nullable']) || false === $this->shouldDeserializeNull) ) { $type = ['name' => 'NULL', 'params' => []]; } diff --git a/tests/Fixtures/BlogPost.php b/tests/Fixtures/BlogPost.php index 81baaab9c..4ef7afffe 100644 --- a/tests/Fixtures/BlogPost.php +++ b/tests/Fixtures/BlogPost.php @@ -88,7 +88,7 @@ class BlogPost private $metadata; /** - * @Type("JMS\Serializer\Tests\Fixtures\Author") + * @Type("?JMS\Serializer\Tests\Fixtures\Author") * @Groups({"post"}) * @XmlElement(namespace="http://www.w3.org/2005/Atom") */ @@ -100,7 +100,7 @@ class BlogPost private $publisher; /** - * @Type("array") + * @Type("?array") * @XmlList(inline=true, entry="tag", namespace="http://purl.org/dc/elements/1.1/"); */ private $tag;