Skip to content

Commit

Permalink
[Serializer] Fix ignoring objects that only implement DenormalizableI…
Browse files Browse the repository at this point in the history
…nterface
  • Loading branch information
Petar Obradović committed Jun 1, 2023
1 parent 1905a88 commit 4d46506
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions Normalizer/CustomNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
];
}

Expand Down
9 changes: 9 additions & 0 deletions Tests/SerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 4d46506

Please sign in to comment.