Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[Serializer] deserialize from xml: Fix a collection that contains the only one element#27326
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
Uh oh!
There was an error while loading.Please reload this page.
Conversation
nicolas-grekas commentedMay 30, 2018
thank you@webnet-fr |
webnet-fr commentedMay 30, 2018
Thank you for your hint@nicolas-grekas ( There are still an strange error in tests for < PHP 7.0 which I am not sure how to deal with. Could you have a look, please? |
| returntrue; | ||
| } | ||
| publicfunctioninstantiateObject(array &$data,$class,array &$context,\ReflectionClass$reflectionClass,$allowedAttributes,string$format =null) |
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.
the "string" type hint is illegal here, branch 3.4 should work on PHP5.5
nicolas-grekas left a comment
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.
(failure unrelated)
dunglas commentedMay 31, 2018 • 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'm not a fan of adding such quirks in the main normalizer hierarchy... But I've no better idea right now. Maybe should we introduce a specific XML normalizer instead? |
nicolas-grekas commentedJun 8, 2018
@dunglas: good enough as is? |
fabpot commentedJun 10, 2018
Thank you@webnet-fr. |
…ontains the only one element (webnet-fr)This PR was squashed before being merged into the 3.4 branch (closes#27326).Discussion----------[Serializer] deserialize from xml: Fix a collection that contains the only one element| Q | A| ------------- | ---| Branch? | 3.4| Bug fix? | yes| New feature? | no| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets |#27279| License | MIT| Doc PR |In xml when parent node (`restaurants`) contains several children nodes with the same tag (`restaurant`) it is clear that the children form a collection:```restaurants = {array} [1] restaurant = {array} [2] 0 = {array} [2] name = "Some restaurant name" type = "Chinese" 1 = {array} [2] name = "Another restaurant name" type = "Italian"```Afterwards the object denormalizer has no problem to create a collection of restaurants.But when there is only one child (`restaurant`) the decoded normalized array will not contain a collection:```restaurants = {array} [1] restaurant = {array} [2] name = "Some restaurant name" type = "Chinese"```In this situation the object denormalizer threw unexpected exception. This PR modifies `AbstractObjectNormalizer` that is it will fill a collection containing the sole element properly.Commits-------1f346f4 [Serializer] deserialize from xml: Fix a collection that contains the only one element
| class SerializerCollectionDummyimplements \Symfony\Component\Serializer\SerializerInterface, \Symfony\Component\Serializer\Normalizer\DenormalizerInterface | ||
| { | ||
| /** @var \Symfony\Component\Serializer\Normalizer\DenormalizerInterface */ |
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.
please review24b6848 and report any mistake
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.
Looks good to me
nano-freelancer commentedSep 20, 2018
@webnet-fr as i wrote in issue27279, provided above fix should be extended also forjson-data Thanks |
In xml when parent node (
restaurants) contains several children nodes with the same tag (restaurant) it is clear that the children form a collection:Afterwards the object denormalizer has no problem to create a collection of restaurants.
But when there is only one child (
restaurant) the decoded normalized array will not contain a collection:In this situation the object denormalizer threw unexpected exception. This PR modifies
AbstractObjectNormalizerthat is it will fill a collection containing the sole element properly.