Skip to content

Wrong parameter's name for Serializer Yaml configuration #21010

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
b-viguier opened this issue May 28, 2025 · 0 comments
Closed

Wrong parameter's name for Serializer Yaml configuration #21010

b-viguier opened this issue May 28, 2025 · 0 comments
Labels
hasPR A Pull Request has already been submitted for this issue. Serializer

Comments

@b-viguier
Copy link

b-viguier commented May 28, 2025

Serializer's documentation explains that we can specify a context specific to normalization or denormalization using normalizationContext and denormalizationContext keys in Yaml configuration:

https://github.com/symfony/symfony-docs/blob/6.4/serializer.rst?plain=1#L523-L524

# config/serializer/person.yaml
App\Model\Person:
    attributes:
        createdAt:
            contexts:
                - normalizationContext: { datetime_format: 'Y-m-d' }
                  denormalizationContext: { datetime_format: !php/const \DateTime::RFC3339 }

In the other hand, the YamlFileLoader is looking for normalization_context and denormalization_context keys:

https://github.com/symfony/symfony/blob/b43330568c434747ec5efe2aed7c14c7995e551a/src/Symfony/Component/Serializer/Mapping/Loader/YamlFileLoader.php#L114-L120

if ($context = $line['normalization_context'] ?? false) {
    $attributeMetadata->setNormalizationContextForGroups($context, $groups);
}

if ($context = $line['denormalization_context'] ?? false) {
    $attributeMetadata->setDenormalizationContextForGroups($context, $groups);
}

Links above are for 6.4 but it seems to be there from the beginning, nothing changed in the code. Confusion may be due to the name of the corresponding attribute.

@xabbuh xabbuh added the hasPR A Pull Request has already been submitted for this issue. label May 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hasPR A Pull Request has already been submitted for this issue. Serializer
Projects
None yet
Development

No branches or pull requests

2 participants