Skip to content

Conversation

nicolas-grekas
Copy link
Member

@nicolas-grekas nicolas-grekas commented Aug 26, 2025

Q A
Branch? 7.4
Bug fix? no
New feature? yes
Deprecations? yes
Issues -
License MIT

Very close to #61528
Prerequisite for #61287

At the moment, serialization attributes are read at runtime when framework.serialization.enable_attributes is true.

This means they don't fit for bundles nor can't they be warmed up.

This PR fixes both issues by using a new serializer.attribute_metadata resource tag, that's turned into a list of classes to parse for attributes at compile-time.

For bundles and for apps, the tag is added by explicit service configuration:

        ->set('my_bundle.api_resource.product', Product::class)
            ->resourceTag('serializer.attribute_metadata')

Unlike validation where we have constraint attributes to auto-discover service resources, serialization doesn't have any corresponding hooks. We do have a few like #[DiscriminatorMap] of #[Groups], but relying on those would miss many more classes that are meant for serialization. Maybe we could introduce an attribute that'd hint that some class is serializable by the component (and require the attribute at some point in the future?)

@nicolas-grekas nicolas-grekas force-pushed the serializer.attribute_metadata branch from e21e3a8 to bc6e054 Compare September 3, 2025 17:28
@nicolas-grekas nicolas-grekas merged commit bde5221 into symfony:7.4 Sep 3, 2025
10 of 12 checks passed
@nicolas-grekas nicolas-grekas deleted the serializer.attribute_metadata branch September 3, 2025 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants