Skip to content

[Serializer] Error when using a named argument in the "normalize" method of the NormalizerInterface. #53326

@AlessandroAmos

Description

@AlessandroAmos

Symfony version(s) affected

6.0 - 7.0

Description

The implementation of the NormalizerInterface in the Serializer class uses a different name for the first argument ($data) compared to the interface ($object), causing an error when attempting to invoke the normalize method with named arguments.

How to reproduce

Simply make a call to normalize by passing named arguments.

public function userToArray(NormalizerInterface $normalizer, User $user): array
{
    return $normalizer->normalize(
        object: $user,
        format: 'json',
        context: [
            'user:hide_email' => true,
        ]
    );
}

I have an exception "Unknown named parameter $object."

Possible Solution

Rename the argument name $object to $data in NormalizerInterface -> normalize

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