Skip to content
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

[Serializer] Groups annotation/attribute on class #49594

Merged
merged 1 commit into from Aug 1, 2023

Conversation

Brajk19
Copy link
Contributor

@Brajk19 Brajk19 commented Mar 3, 2023

Q A
Branch? 6.4
Bug fix? no
New feature? yes
Deprecations? no
Tickets
License MIT
Doc PR TODO

This change adds option to use Groups attribute on class. Doing that will add specified group to each property.

Example, this:

class MyEntity
{
    #[Groups('group1')]
    private $foo;
    #[Groups('group1')]
    private $bar;

// getters and setters...
}

can be replaced with this

#[Groups('group1')]
class MyEntity
{
    private $foo;
    private $bar;

// getters and setters...
}

It also works with promoted properties.
This:

class View
{
    public function __construct(
        #[Groups('group1')] public readonly string $foo,
        #[Groups('group1')] public readonly string $bar
    ){
    }
}

can be replaced with this:

#[Groups('group1')]
class View
{
    public function __construct(
        public readonly string $foo,
        public readonly string $bar
    ){
    }
}

@carsonbot
Copy link

Hey!

To help keep things organized, we don't allow "Draft" pull requests. Could you please click the "ready for review" button or close this PR and open a new one when you are done?

Note that a pull request does not have to be "perfect" or "ready for merge" when you first open it. We just want it to be ready for a first review.

Cheers!

Carsonbot

@Brajk19 Brajk19 marked this pull request as ready for review March 3, 2023 21:01
@Brajk19 Brajk19 requested a review from dunglas as a code owner March 3, 2023 21:01
@carsonbot carsonbot added this to the 6.3 milestone Mar 3, 2023
@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has a contribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (see https://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (see https://symfony.com/releases)
  • Features and deprecations must be submitted against the 6.3 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@Brajk19 Brajk19 changed the title Serializer groups on class [Serializer] Groups annotation/attribute on class Mar 3, 2023
@Brajk19 Brajk19 force-pushed the serializer-groups-on-class branch from abe5f21 to 2e092d4 Compare March 3, 2023 21:15
@alexislefebvre
Copy link
Contributor

I suggest to not support the annotation @Groups({"a"}), and only support the attribute #[Groups('a')].

See:

@OskarStark
Copy link
Contributor

Open to finish this PR?

@derrabus
Copy link
Member

I suggest to not support the annotation @Groups({"a"}), and only support the attribute #[Groups('a')].

Because of the way we merge annotations and attributes on the reader level already, it might be more complicated to exclude Doctrine Annotations from this feature than to just support them.

@Brajk19 Brajk19 force-pushed the serializer-groups-on-class branch from 44d0b0e to ac82af8 Compare July 27, 2023 11:08
@Brajk19
Copy link
Contributor Author

Brajk19 commented Jul 27, 2023

I suggest to not support the annotation @Groups({"a"}), and only support the attribute #[Groups('a')].

Because of the way we merge annotations and attributes on the reader level already, it might be more complicated to exclude Doctrine Annotations from this feature than to just support them.

Agreed. I'll leave it as is then.

src/Symfony/Component/Serializer/CHANGELOG.md Outdated Show resolved Hide resolved
@fabpot fabpot force-pushed the serializer-groups-on-class branch from f0e6f35 to ef2c30c Compare August 1, 2023 07:19
@fabpot
Copy link
Member

fabpot commented Aug 1, 2023

Thank you @Brajk19.

@fabpot fabpot merged commit 15e082d into symfony:6.4 Aug 1, 2023
6 of 9 checks passed
This was referenced Oct 21, 2023
@tacman
Copy link
Contributor

tacman commented Nov 15, 2023

This is great. Is there a way to exclude a property? For example, the password_hash on a User entity.

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.

None yet

10 participants