Description
Symfony version(s) affected
7.1.*
Description
Adding COLLECT_DENORMALIZATION_ERRORS
to the framework.default_context
has no effect if you want to collect denormalization errors for all ->denormalize
calls. It only works, if it is added to each ->denormalize
call as an extra argument.
How to reproduce
Framework Config
# config/packages/framework.yaml
framework:
# ...
serializer:
default_context:
!php/const Symfony\Component\Serializer\Normalizer\DenormalizerInterface::COLLECT_DENORMALIZATION_ERRORS: true
Object
final readonly class Foo
{
public function __construct(
public string $bar,
) {}
}
Denormalize call:
public function __construct(
private DenormalizerInterface $denormalizer,
) {
}
public function __invoke(): void
{
$this->denormalizer->denormalize(
data: [],
type: Foo::class,
);
}
Expected: \Symfony\Component\Serializer\Exception\PartialDenormalizationException
is thrown
Actual: \Symfony\Component\Serializer\Exception\MissingConstructorArgumentsException
is thrown
Possible Solution
If this is intended behaviour, I would suggest to add this to the documentation here, that it cannot be set as a default.
If this is not an intended behaviour, maybe there is a way to get the context of the used $normalizer
at this line in the Serializer Class and use it as another check if it is not set in $context
.
Additional Context
No response