Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
[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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
@derrabus You're probably very busy, but I'm really curious to hear your feedback on this 😊 |
@mtarld@nicolas-grekas Friendly ping to pick your brain on this topic, since you worked on the discriminator mapping in#52681. I'm curious to hear if my approach makes sense, or that I should investigate time in finding an alternative solution. Any advice is much appreciated, thanks 😊 |
src/Symfony/Component/Serializer/Tests/Fixtures/DummyMessageNumberFour.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Serializer/Normalizer/PropertyNormalizer.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
ad5ce53
to930d792
CompareThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Works for me. BC is not affected since no API changes. The behavior change is the bug fix so no regression either to me.
src/Symfony/Component/Serializer/Normalizer/PropertyNormalizer.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
One last thing, otherwise, LGTM!
src/Symfony/Component/Serializer/Tests/Normalizer/PropertyNormalizerTest.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Fixessymfony#60214Currently it's not possible to serialize an object using the PropertyNormalizer when aDiscriminatorMap 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 fordiscriminators. 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.
Thanks for the help@mtarld and@nicolas-grekas 🎉 The failing test is unrelated to these changes. |
Thank you@ruudk. |
f37df38
intosymfony:6.4Uh oh!
There was an error while loading.Please reload this page.
VitekSkrip commentedJun 19, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I probably got similar problem at symfony 7.1.5 Test Case:
Runs this: $serialized = $this->serializer->serialize($payload, 'json');
But then i drop Ignore attribute - it passes!! {"type":"base_payload","a":"string","aString":true} |
@VitekSkrip please give this PR a try and create a new issue if it doesn't fix it for you then. |
VitekSkrip commentedJun 19, 2025
what version of symfony or symfony/serializer should i use then? |
ruudk commentedJun 19, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@VitekSkrip This was just merged to 6.4.x.dev. It will take some time before it is merged to 7.2 and 7.3. Since you are on 7.1 you won't get it, unless you upgrade. |
Currently it's not possible to serialize an object using the PropertyNormalizer when a DiscriminatorMap attribute is used.
It produces the following error:
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.