Skip to content

Commit 89092ea

Browse files
JustDylan23fancyweb
authored andcommitted
[Serializer] Fix AbstractObjectNormalizer TypeError on denormalization
1 parent 46dd881 commit 89092ea

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ protected function isAllowedAttribute(object|string $classOrObject, string $attr
296296
* Normalizes the given data to an array. It's particularly useful during
297297
* the denormalization process.
298298
*/
299-
protected function prepareForDenormalization(object|array|null $data): array
299+
protected function prepareForDenormalization(mixed $data): array
300300
{
301301
return (array) $data;
302302
}

src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Doctrine\Common\Annotations\AnnotationReader;
1515
use PHPUnit\Framework\TestCase;
1616
use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor;
17+
use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
1718
use Symfony\Component\PropertyInfo\Type;
1819
use Symfony\Component\Serializer\Exception\ExtraAttributesException;
1920
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
@@ -387,6 +388,17 @@ public function testNormalizeEmptyObject()
387388
$normalizedData = $normalizer->normalize(new EmptyDummy(), 'any', ['preserve_empty_objects' => true]);
388389
$this->assertEquals(new \ArrayObject(), $normalizedData);
389390
}
391+
392+
public function testDenormalizeRecursiveWithObjectAttributeWithStringValue()
393+
{
394+
$extractor = new ReflectionExtractor();
395+
$normalizer = new ObjectNormalizer(null, null, null, $extractor);
396+
$serializer = new Serializer([$normalizer]);
397+
398+
$obj = $serializer->denormalize(['inner' => 'foo'], ObjectOuter::class);
399+
400+
$this->assertInstanceOf(ObjectInner::class, $obj->getInner());
401+
}
390402
}
391403

392404
class AbstractObjectNormalizerDummy extends AbstractObjectNormalizer

0 commit comments

Comments
 (0)