Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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

Merged
fabpot merged 1 commit intosymfony:3.4fromwebnet-fr:fix-27279
Jun 10, 2018

Conversation

@webnet-fr
Copy link
Contributor

QA
Branch?3.4
Bug fix?yes
New feature?no
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#27279
LicenseMIT
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 modifiesAbstractObjectNormalizer that is it will fill a collection containing the sole element properly.

Koc reacted with hooray emoji
@nicolas-grekasnicolas-grekas changed the titledeserialize from xml: Fix a collection that contains the only one ele…[Serializer] deserialize from xml: Fix a collection that contains the only one elementMay 21, 2018
@nicolas-grekasnicolas-grekas added this to the3.4 milestoneMay 21, 2018
@nicolas-grekas
Copy link
Member

thank you@webnet-fr
there are some failures on 5.5 that look related. I think you're using deprecated mock functions for now.
Can you please have a look to make tests green?

@webnet-fr
Copy link
ContributorAuthor

Thank you for your hint@nicolas-grekas (getMockBuilder should have been used).

There are still an strange error in tests for < PHP 7.0 which I am not sure how to deal with.
The list of arguments ofAbstractNormalizer::instantiateObject as for Symfony 3.4 is:
(array &$data, $class, array &$context, \ReflectionClass $reflectionClass, $allowedAttributes/*, string $format = null*/)
But in tests it seems likestring $format = null is uncommented which leads to errors for < PHP 7.0.

Could you have a look, please?

returntrue;
}

publicfunctioninstantiateObject(array &$data,$class,array &$context,\ReflectionClass$reflectionClass,$allowedAttributes,string$format =null)

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

Copy link
Member

@nicolas-grekasnicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

(failure unrelated)

@dunglas
Copy link
Member

dunglas commentedMay 31, 2018
edited
Loading

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?

Koc reacted with thumbs up emoji

@nicolas-grekas
Copy link
Member

@dunglas: good enough as is?

@fabpot
Copy link
Member

Thank you@webnet-fr.

@fabpotfabpot merged commit1f346f4 intosymfony:3.4Jun 10, 2018
fabpot added a commit that referenced this pull requestJun 10, 2018
…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 */

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Looks good to me

This was referencedJun 25, 2018
@nano-freelancer
Copy link

@webnet-fr as i wrote in issue27279, provided above fix should be extended also forjson-data

Thanks

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@dunglasdunglasdunglas approved these changes

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

@fabpotfabpotfabpot approved these changes

Assignees

No one assigned

Projects

None yet

Milestone

3.4

Development

Successfully merging this pull request may close these issues.

6 participants

@webnet-fr@nicolas-grekas@dunglas@fabpot@nano-freelancer@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp