From 9efa1142d4231568b97cac75029670fabb56a7a5 Mon Sep 17 00:00:00 2001 From: Asmir Mustafic Date: Thu, 2 May 2019 23:46:49 +0200 Subject: [PATCH] allow to control null deserialization --- src/GraphNavigator/DeserializationGraphNavigator.php | 4 ++-- tests/Fixtures/BlogPost.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) 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;