Skip to content

[Serializer] Add support for discriminator map in property normalizer #60511

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 1 commit into
base: 6.4
Choose a base branch
from

Conversation

ruudk
Copy link
Contributor

@ruudk ruudk commented May 22, 2025

Q A
Branch? 6.4
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #60214
License MIT

Currently it's not possible to serialize an object using the PropertyNormalizer when a DiscriminatorMap attribute is used.

It produces the following error:

Symfony\Component\Serializer\Exception\NotNormalizableValueException: Type property "type" not found
for the abstract object "Symfony\Component\Serializer\Tests\Fixtures\DummyMessageInterface".

The ObjectNormalizer overrides the getAllowedAttributes from AbstractNormalizer and adds support for discriminators. But the PropertyNormalizer does not do this. Therefore it doesn't work.

For now, we copy the logic from ObjectNormalizer to PropertyNormalizer and the problem goes away.

Fixes symfony#60214

Currently it's not possible to serialize an object using the PropertyNormalizer when a
DiscriminatorMap attribute is used.

It produces the following error:

> Symfony\Component\Serializer\Exception\NotNormalizableValueException: Type property "type" not found
> for the abstract object "Symfony\Component\Serializer\Tests\Fixtures\DummyMessageInterface".

The ObjectNormalizer overrides the `getAllowedAttributes` from AbstractNormalizer and adds support for
discriminators. But the PropertyNormalizer does not do this. Therefore it doesn't work.

For now, we copy the logic from ObjectNormalizer to PropertyNormalizer and the problem goes away.
@carsonbot

This comment was marked as resolved.

@carsonbot carsonbot added this to the 7.3 milestone May 22, 2025
@ruudk ruudk changed the base branch from 7.3 to 6.4 May 22, 2025 11:30
@alexandre-daubois alexandre-daubois modified the milestones: 7.3, 6.4 May 23, 2025
@ruudk
Copy link
Contributor Author

ruudk commented May 23, 2025

@derrabus You're probably very busy, but I'm really curious to hear your feedback on this 😊

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.

[Serializer] Discriminator is removed when #[Ignore] attribute used on unrelated method
3 participants