Skip to content

Conversation

@MatTheCat
Copy link
Contributor

@MatTheCat MatTheCat commented Jul 31, 2025

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

Split from #60568

@MatTheCat
Copy link
Contributor Author

high-deps failure seems related to #61101; how could it be fixed?

@MatTheCat MatTheCat force-pushed the deprecate_serializer_xml_loader branch 3 times, most recently from 2422e54 to ed71ee6 Compare August 4, 2025 07:47
@MatTheCat MatTheCat force-pushed the deprecate_serializer_xml_loader branch 2 times, most recently from f95c212 to a0ad8e3 Compare August 20, 2025 12:58
@MatTheCat MatTheCat force-pushed the deprecate_serializer_xml_loader branch from a0ad8e3 to 600e7a3 Compare August 26, 2025 11:10
@MatTheCat MatTheCat force-pushed the deprecate_serializer_xml_loader branch from 600e7a3 to e08eeea Compare September 3, 2025 16:44
nicolas-grekas added a commit that referenced this pull request Sep 3, 2025
…-time serialization metadata (nicolas-grekas)

This PR was merged into the 7.4 branch.

Discussion
----------

[Serializer] Allow using attributes to declare compile-time serialization metadata

| 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:
```php
        ->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?)

Commits
-------

bc6e054 [Serializer] Allow using attributes to declare compile-time serialization metadata
@nicolas-grekas
Copy link
Member

Let me close for reasons explained in #61288 (comment).
A big thank you for pushing this forward, it made us realize that we have some more steps ahead before being able to deprecate.
But I definitely want to reconsider on 8.x!

@MatTheCat MatTheCat deleted the deprecate_serializer_xml_loader branch September 4, 2025 15:35
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.

3 participants