Comments (4)
I figured out why this happens. The type in the projectsData
example is correctly detected as ProjectData
class because the property name is considered plural. When that happens the type extractor looks for the method with add
prefix first and from that it detects the correct type. With projectsDto
the name is considered singular, so it first looks for method with set
prefix and since it's array it deserializes into a simple array.
To fix this you just have to add a phpdoc typehint to your property
#[SerializedName('projectDto')]
/**
* @var \App\Dtos\ProjectData[]
*/
private array $projectsDto = [];
I am not sure if this is considered a bug. In my opinion it is, we should always check for add
methods first since they are most likely to have a type hint in the argument, but I might be missing something. Looking for advice here.
Depending on this being considered a bug I can either create a fix or update the docs and mention this case.
from symfony.
Thank you @evrinoma for creating this bug report! This indeed looks
like a bug. I reproduced the bug in the "main" branch of
https://github.com/EugeneKwasny/issue-5475-bug-repoducer
Status: Reviewed
from symfony.
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.
from symfony.
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'm afraid your assumption seems to be incorrect, and it won't work as expected
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.
from symfony.
Related Issues (20)
- [Serializer] Inconsistent Naming of First Argument in normalize() Method between NormalizerInterface and Serializer Class
- Filesystem requires symfony/process after 6.4.7./7.0.7 HOT 1
- Ignore can only be added on methods beginning with "get", "is", "has" or "set".
- [Messenger] Argument #1 ($tableName) must be of type string HOT 2
- Attempted to call an undefined method named "setCallbackWrapper" of class "Symfony\Component\Cache\Adapter\TraceableAdapter". HOT 1
- symfony/serializer version 7.0.7 now throws NotNormalizableValueException HOT 5
- [Serializer] `ObjectNormalizer` breaks when used with `PropertyInfoExtractorInterface` HOT 5
- [HttpClient] Segfault CurlResponse HOT 1
- [Translation] `translation:extract` with bundle - should also extract translations from PHP code HOT 1
- [RFC] include a new dev dependency `twig-cs-fixer` in the codebase HOT 6
- [DoctrineBridge] Possible cirtucal references of lazy-service (listener) HOT 3
- [Messenger][Doctrine] cleanup only the configured queue_name
- BicValidator/IbanValidator value normalization HOT 1
- [DependencyInjection] Can not replace arguments if none have been configured yet - InlineAutowire HOT 5
- [Routing] Output IDN domains instead of punycode for `UrlGeneratorInterface::ABSOLUTE_URL`
- [Ldap] UpdateOperation toArray() function throws exception when using LDAP_MODIFY_BATCH_REMOVE_ALL operation type HOT 4
- [Messenger][AMQP] Allow to opt out to autosetup delay exchange in configuration HOT 1
- [Validator] Class "Locale" not found HOT 1
- The configuration of packages in the application is ignored after they are applied inside `prependExtension` the bundle HOT 4
- [symfony/yaml] Yaml::dump cannot properly parse array of arrays / nested arrays HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from symfony.