Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Serializer] Setting COLLECT_DENORMALIZATION_ERRORS in default_context of framework config has no effect #58628

Copy link
Copy link
Closed
@freddytqg

Description

@freddytqg
Issue body actions

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.