From 4d465068ed33a34a208069341438534fdb0e5a96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petar=20Obradovi=C4=87?= Date: Thu, 1 Jun 2023 11:47:23 +0200 Subject: [PATCH] [Serializer] Fix ignoring objects that only implement DenormalizableInterface --- Normalizer/CustomNormalizer.php | 1 + Tests/SerializerTest.php | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/Normalizer/CustomNormalizer.php b/Normalizer/CustomNormalizer.php index dd64c9dca..7e67a31a9 100644 --- a/Normalizer/CustomNormalizer.php +++ b/Normalizer/CustomNormalizer.php @@ -28,6 +28,7 @@ public function getSupportedTypes(?string $format): array { return [ NormalizableInterface::class => __CLASS__ === static::class || $this->hasCacheableSupportsMethod(), + DenormalizableInterface::class => __CLASS__ === static::class || $this->hasCacheableSupportsMethod(), ]; } diff --git a/Tests/SerializerTest.php b/Tests/SerializerTest.php index 914458fb4..f4a164dc5 100644 --- a/Tests/SerializerTest.php +++ b/Tests/SerializerTest.php @@ -50,6 +50,7 @@ use Symfony\Component\Serializer\Tests\Fixtures\Annotations\AbstractDummy; use Symfony\Component\Serializer\Tests\Fixtures\Annotations\AbstractDummyFirstChild; use Symfony\Component\Serializer\Tests\Fixtures\Annotations\AbstractDummySecondChild; +use Symfony\Component\Serializer\Tests\Fixtures\DenormalizableDummy; use Symfony\Component\Serializer\Tests\Fixtures\DummyFirstChildQuux; use Symfony\Component\Serializer\Tests\Fixtures\DummyMessageInterface; use Symfony\Component\Serializer\Tests\Fixtures\DummyMessageNumberOne; @@ -120,6 +121,14 @@ public function testDenormalizeNoMatch() $serializer->denormalize('foo', 'stdClass'); } + public function testDenormalizeOnObjectThatOnlySupportsDenormalization() + { + $serializer = new Serializer([new CustomNormalizer()]); + + $obj = $serializer->denormalize('foo', (new DenormalizableDummy())::class, 'xml'); + $this->assertInstanceOf(DenormalizableDummy::class, $obj); + } + public function testDenormalizeOnNormalizer() { $this->expectException(UnexpectedValueException::class);