Skip to content

Wrong parameter's name for Serializer Yaml configuration #21010

Closed
@b-viguier

Description

@b-viguier

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    SerializerhasPRA Pull Request has already been submitted for this issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions