Skip to content

[Serializer] Fix AbstractObjectNormalizer TypeError on denormalization #44881

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ protected function isAllowedAttribute(object|string $classOrObject, string $attr
* Normalizes the given data to an array. It's particularly useful during
* the denormalization process.
*/
protected function prepareForDenormalization(object|array|null $data): array
protected function prepareForDenormalization(mixed $data): array
{
return (array) $data;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor;
use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Mapping\AttributeMetadata;
use Symfony\Component\Serializer\Mapping\ClassMetadata;
Expand Down Expand Up @@ -217,4 +218,15 @@ public function testIgnore()

$this->assertSame([], $normalizer->normalize($dummy));
}

public function testDenormalizeRecursiveWithObjectAttributeWithStringValue()
{
$extractor = new ReflectionExtractor();
$normalizer = new ObjectNormalizer(null, null, null, $extractor);
$serializer = new Serializer([$normalizer]);

$obj = $serializer->denormalize(['inner' => 'foo'], ObjectOuter::class);

$this->assertInstanceOf(ObjectInner::class, $obj->getInner());
}
}