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

Add whole tree to Groups or set group to whole class #949

Open
realjjaveweb opened this issue Apr 8, 2024 · 1 comment
Open

Add whole tree to Groups or set group to whole class #949

realjjaveweb opened this issue Apr 8, 2024 · 1 comment

Comments

@realjjaveweb
Copy link

Q A
Bug report? no
Feature request? yes
BC Break report? no
RFC? no

I am looking for a way how to mark the whole DTO tree as a part of a serializer group, because #[Serializer\Groups([... works only on the property levels, then if you request the group in the serialization context, any property - whatsoever nested - has to have the group defined.

<?php
// ...
class ParentDTO
{
    // ... 
    #[Serializer\Groups([...
    private KidDTO $kidDTO;
    // ...
}

Now when the groups are used during serialization to JSON through SerializationContext, the $kidDTO will result in an empty object kidDTO: {} unless, the groups are added to all its properties.

This is very unhandy, since some DTOs are so granular and shared among other DTOs that adding all groups of all DTOs from the parent tree to all the subtree properties is simply unrealistic and would create unnecessary code mess.

Is there a way how to do one of the following:

  1. Set on the property that for a certain group, the whole subtree should be included? (preferred)
  2. Define the Groups on the class level? (compromise)

(1.) would especially be appreciated in case I want to nest some external DTO where I can't really add my custom serialization groups.

@scyzoryck
Copy link
Collaborator

Hi!

I think at the moment serialiser do not support such options. Feel free to propose some Pull Request with the changes for it - I think it should be kinda easy to implement in GroupsExclusionStrategy :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants