-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[Serializer] use the NormalizerAwareInterface
to prevent circular references
#16826
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
Conversation
This implementation would cause an infinite recursion because the serializer would inject itself as normalizer and dispatch the normalize call to our custom normalizer again. |
The infinite recursion can be avoided with this trick: https://symfonycasts.com/screencast/api-platform-security/normalizer-aware#avoiding-recursion-with-a-context-flan |
As written in the API Platform documentation, this way to do is actually working if adding a flag in the context. |
I guess we can close here and open a new PR to document symfony/symfony#46625. |
@HeahDude Not sure actually :) This example is what prevents us from enabling the serializer panel by default as it builds on an autowired concrete class instead of an interface. The alternatives I can think of:
If we are not happy with both approaches, that probably means we need to work on adding a better way to give |
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.
As written in the API Platform documentation, this way to do is actually working if adding a flag in the context.
So we need to add a mention like the API P doc to explain the flag in context.
Thinking twice about this, I'd advocate for the explicit DI approach (second alternative in #16826 (comment)) |
What should we do with this PR? Merge, close or keep working on it? Thanks! |
NormalizerAwareInterface
to prevent circular references
I think it misses two things:
At least one of these points should be done to prevent infinite recursion. |
closing as I think this has been fixed in #19532 |
see symfony/maker-bundle#1252