JMSSerializerBundle
JMSSerializerBundle copied to clipboard
Add whole tree to Groups or set group to whole class
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:
- Set on the property that for a certain group, the whole subtree should be included? (preferred)
- 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.