Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[Serializer] Add#[ExtendsSerializationFor] to declare new serialization attributes for a class#61563
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
8ab243e tod0e4db4Compare#[ExtendsSerializationFor] to declare new serialization attributes for a classfabpot added a commit that referenced this pull requestSep 2, 2025
…ct classes for resource definitions (nicolas-grekas)This PR was merged into the 7.4 branch.Discussion----------[DependencyInjection] Parse attributes found on abstract classes for resource definitions| Q | A| ------------- | ---| Branch? | 7.4| Bug fix? | no| New feature? | yes| Deprecations? | no| Issues | -| License | MITThis PR improves support for resource definitions by allowing to parse attributes on abstract classes.This can be useful for PRs like#61563 and#61545, so that the attribute proposed there could be set on abstract classes.Commits-------6571f7b [DependencyInjection] Parse attributes found on abstract classes for resource definitions
…ation attributes for a class
d0e4db4 to386f949Comparealexandre-daubois approved these changesSep 9, 2025
fabpot approved these changesSep 10, 2025
Thank you@nicolas-grekas. |
e0b50a7 intosymfony:7.4 10 of 12 checks passed
Uh oh!
There was an error while loading.Please reload this page.
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading.Please reload this page.
This PR builds on#61532
It's a sibling of#61545
I propose to add a
#[ExtendsSerializationFor]attribute that allows adding serialization attributes to another class.This is typically needed for third party classes. For context, Sylius has a nice doc about this:
https://docs.sylius.com/the-customization-guide/customizing-serialization-of-api
At the moment, the only way to achieve this is by declaring the new attributes in the (hardcoded)
config/serialization/folder, using either xml or yaml. No attributes.With this PR, one will be able to define those extra serialization attributes using PHP attributes, set on classes that'd mirror the properties/getters of the targeted class. The compiler pass will ensure that all properties/getters declared in these source classes also exist in the target class. (source = the app's class that declares the new serialization attributes; target = the existing class to add serialization attributes to.)
(I made the class abstract because it's not supposed to be instantiated - but it's not mandatory.)
Here are the basics of how this works:
#[ExtendsSerializationFor(Target::class)]are collected and validated: the container checks that members declared on the source exist on the target. If not, aMappingExceptionis thrown.