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
[Serializer] Restrictions #54753
Comments
Thank you @evrinoma for creating this bug report! This indeed looks Status: Reviewed |
I figured out why this happens. The type in the To fix this you just have to add a phpdoc typehint to your property
I am not sure if this is considered a bug. In my opinion it is, we should always check for Depending on this being considered a bug I can either create a fix or update the docs and mention this case. |
I'm afraid your assumption seems to be incorrect, and it won't work as expected. Could you please take a closer look at the code, not just at the ReflectionExtractor, but also at this problematic part of the EnglishInflector. In this file, variable names are hardcoded in reverse, and data is present in the list, but not dto. In common, It seems odd if I were to use German and name a variable projektDaten, and then the serializer behaves differently. It appears to be a suboptimal solution that contradicts the principles of KISS (Keep It Simple, Stupid). Why not simply allow users to specify the data type for a specific field via context? Why use reflection to study fields and analyze field and method names? Speed and simplicity are crucial for serializers, and if we have to struggle with every variable name, then what's the point of having it? It feels like a feeble imitation of artificial intelligence. More than that now it's slower than oldest JMS serializer. |
I agree with you that behavior should not be affected by property naming, but this is a pretty niche edge case. To encounter this you have to not use the docblocks, which(I hope) is pretty rare.
I have tested it with the docblock and it works, I can make a PR to the bug-reproducer repo if you're interested. It is possible to add support to setting types via context or configuration, but I feel like that would get rejected due to the design differences. |
Symfony version(s) affected
6.4
Description
Hi everyone,
I'd like to ask why Symfony Serializer has name restrictions. Here are two code examples, and they give me two different results
I would suggest that it's incorrect behavior and completely undocumented. I'm feeling a bit sad about switching from JMS Serializer.
thanks in advance.
How to reproduce
In the second example, I would like to rename 'projectsDto' to 'projectsData' along with its associated methods.
Possible Solution
No response
Additional Context
No response
The text was updated successfully, but these errors were encountered: