Closed
Description
Symfony version(s) affected: 5.1.8
Description
It's impossible to denormalize into a scalar value when using the unwrap path feature, because the scalar value check is done before applying the UnwrappingDenormalizer.
How to reproduce
use Symfony\Component\Serializer\Normalizer\UnwrappingDenormalizer;
$result = $serializer->deserialize(
'{"baz": "test"}',
'string',
'json',
[UnwrappingDenormalizer::UNWRAP_PATH => '[baz]']
);
// expected result
// $result === "test"
// actual result
// Symfony\Component\Serializer\Exception\NotNormalizableValueException: Data expected to be of type "string" ("array" given).
Possible fix
Introduce a ScalarDenormalizer instead of checking the target type inside the Serializer class.