Skip to content

[Serializer] Enabled mapping configuration via attributes #38525

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

Merged
merged 1 commit into from
Oct 12, 2020

Conversation

derrabus
Copy link
Member

Q A
Branch? 5.x
Bug fix? no
New feature? yes
Deprecations? no
Tickets N/A
License MIT
Doc PR TODO

Let's use attributes for the serializer mapping configuration!

class MyEntity
{
    #[Groups(['list', 'detail])]
    #[SerializedName('some-property')]
    public $someProperty;

    #[Ignore]
    public string $secret;
}

@derrabus derrabus requested a review from dunglas as a code owner October 12, 2020 11:43
@derrabus derrabus force-pushed the improvement/serializer-attributes branch 2 times, most recently from 62248c9 to b5953cb Compare October 12, 2020 11:54
@derrabus
Copy link
Member Author

I was wondering is we should make the Groups attribute variadic. Instead of…

#[Groups(['list', 'detail'])]

… we could then write…

#[Groups('list', 'detail')]

This would look a bit nicer, but adding additional properties in the future would get messy.

@nicolas-grekas nicolas-grekas added this to the 5.2 milestone Oct 12, 2020
@fabpot
Copy link
Member

fabpot commented Oct 12, 2020

@derrabus Can you have a look at the failing tests?

@derrabus derrabus force-pushed the improvement/serializer-attributes branch from b5953cb to cfb9986 Compare October 12, 2020 12:52
@derrabus
Copy link
Member Author

I used ::class in annotations, but Doctrine Annotations 1.0 does not support that. Should be fixed now.

@fabpot
Copy link
Member

fabpot commented Oct 12, 2020

Thank you @derrabus.

@fabpot fabpot merged commit a319090 into symfony:5.x Oct 12, 2020
@fabpot fabpot mentioned this pull request Oct 14, 2020
derrabus added a commit that referenced this pull request Nov 7, 2020
…ration of routing/serializer without doctrine/annotations (derrabus)

This PR was merged into the 5.2-dev branch.

Discussion
----------

 [FrameworkBundle] Allow to use attribute-based configuration of routing/serializer without doctrine/annotations

| Q             | A
| ------------- | ---
| Branch?       | 5.2
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | N/A
| License       | MIT
| Doc PR        | N/A

Follows #37474, #38525

Currently, we need `doctrine/annotations` to be installed in order to configure routing and serializer via PHP attributes. Given that for both components we can already replace Doctrine Annotations completely, I'd like to get rid of that limitation.

Commits
-------

e5492e2 [FrameworkBundle] Configure PHP Attributes without doctrine/annotations.
@derrabus derrabus deleted the improvement/serializer-attributes branch March 13, 2021 15:22
guillaumesmo added a commit to guillaumesmo/rector-symfony that referenced this pull request Apr 11, 2022
Support for all theses attributes was added in Symfony 5.2, together with the already present Groups attribute
see symfony/symfony#38525

there is only one missing Serializer annotation, but it was added in Symfony 5.4, so I left that one out
symfony/symfony#38525
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.

4 participants