Skip to content

[Serializer] Add AbstractNormalizer::IGNORED_GROUPS to make it possible to ignore groups during serialization #57166

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

Open
wants to merge 3 commits into
base: 7.4
Choose a base branch
from

Conversation

zim32
Copy link

@zim32 zim32 commented May 26, 2024

Q A
Branch? 7.2
Bug fix? no
New feature? yes
Deprecations? no
Issues -
License MIT

This MR makes it possible to ignore some groups during serialization process.
Sometimes it is very handy to ignore some groups, f.e. when serializing response DTO's.

With current Ignore attribute it is not possible to ignore some attribute in one context and leave attribute in another context.

With thish MR is it possible to do something like that:

class SomeClass {
    public function __construct(
        public readonly int $customerId,
        #[Groups(['test-group', 'ignore'])]
        public readonly int $token,
    )
    {
    }
}

// For example I want to ignore `token` attribute when returning http response, but I want it to be present when serializing and saving to the database

$this->serializer->serialize(
    $someObject,
    'json',
    [
        AbstractNormalizer::IGNORED_GROUPS => ['ignore'],
    ]
);

@fabpot fabpot modified the milestones: 7.2, 7.3 Nov 20, 2024
@fabpot fabpot modified the milestones: 7.3, 7.4 May 26, 2025
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.

3 participants