8000 bug #50521 [Serializer] Fix ignoring objects that only implement Deno… · symfony/symfony@7e01a32 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7e01a32

Browse files
bug #50521 [Serializer] Fix ignoring objects that only implement DenormalizableInterface (spideyfusion)
This PR was merged into the 6.3 branch. Discussion ---------- [Serializer] Fix ignoring objects that only implement DenormalizableInterface | Q | A | ------------- | --- | Branch? | 6.3 <!-- see below --> | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | N/A <!-- prefix each issue number with "Fix #", no need to create an issue if none exists, explain below instead --> | License | MIT | Doc PR | N/A <!-- required for new features --> When the #49291 optimization got introduced, the `DenormalizableInterface` type was left out of the `CustomNormalizer` normalizer's `getSupportedTypes` implementation. This prevents us for example, implementing custom deserialization logic for API objects where we can't describe all deserialization rules via attributes. <!-- Replace this notice by a short README for your feature/bugfix. This will help reviewers and should be a good start for the documentation. Additionally (see https://symfony.com/releases): - Always add tests and ensure they pass. - Bug fixes must be submitted against the lowest maintained branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too). - Features and deprecations must be submitted against the latest branch. - For new features, provide some code snippets to help understand usage. - Changelog entry should follow https://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry - Never break backward compatibility (see https://symfony.com/bc). --> Commits ------- a0a3ce1 [Serializer] Fix ignoring objects that only implement DenormalizableInterface
2 parents e5c5a51 + a0a3ce1 commit 7e01a32

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/Symfony/Component/Serializer/Normalizer/CustomNormalizer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public function getSupportedTypes(?string $format): array
2828
{
2929
return [
3030
NormalizableInterface::class => __CLASS__ === static::class || $this->hasCacheableSupportsMethod(),
31+
DenormalizableInterface::class => __CLASS__ === static::class || $this->hasCacheableSupportsMethod(),
3132
];
3233
}
3334

src/Symfony/Component/Serializer/Tests/SerializerTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
use Symfony\Component\Serializer\Tests\Fixtures\Annotations\AbstractDummy;
5151
use Symfony\Component\Serializer\Tests\Fixtures\Annotations\AbstractDummyFirstChild;
5252
use Symfony\Component\Serializer\Tests\Fixtures\Annotations\AbstractDummySecondChild;
53+
use Symfony\Component\Serializer\Tests\Fixtures\DenormalizableDummy;
5354
use Symfony\Component\Serializer\Tests\Fixtures\DummyFirstChildQuux;
5455
use Symfony\Component\Serializer\Tests\Fixtures\DummyMessageInterface;
5556
use Symfony\Component\Serializer\Tests\Fixtures\DummyMessageNumberOne;
@@ -120,6 +121,14 @@ public function testDenormalizeNoMatch()
120121
$serializer->denormalize('foo', 'stdClass');
121122
}
122123

124+
public function testDenormalizeOnObjectThatOnlySupportsDenormalization()
125+
{
126+
$serializer = new Serializer([new CustomNormalizer()]);
127+
128+
$obj = $serializer->denormalize('foo', (new DenormalizableDummy())::class, 'xml');
129+
$this->assertInstanceOf(DenormalizableDummy::class, $obj);
130+
}
131+
123132
public function testDenormalizeOnNormalizer()
124133
{
125134
$this->expectException(UnexpectedValueException::class);

0 commit comments

Comments
 (0)
0