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] do not transform empty \Traversable to Array#36601

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

Conversation

@soyuka
Copy link
Contributor

@soyukasoyuka commentedApr 27, 2020
edited
Loading

QA
Branch?4.4
Bug fix?yes
New feature?no
Deprecations?no
Ticketsna
LicenseMIT
Doc PRna

Today, usingPRESERVE_EMPTY_OBJECTS (introduced in 4.0), the JSON serialization of:

<?php$object = [];$object['foo'] =new \ArrayObject();$object['bar'] =new \ArrayObject(['notempty']);$object['baz'] =new \ArrayObject(['nested' =>new \ArrayObject()]);

Outputs:

{"foo":[],"bar":["notempty"],"baz":{"nested":[]}}

Instead of the expected:

{"foo":{},"bar":["notempty"],"baz":{"nested":{}}}

This issue comes from the Serializer that transformsTraversable to an Arrayhere. Also, theAbstractObjectNormalizerdoesn't support Traversable, but he allows to preserve empty objects.

I propose this patch where the fix doesn't transform aTraversable to an Array. I see another way to patch this in which we could allow empty Traversable in theAbstractObjectNormalizer (not sure it's better though). See attachedother-fix.patch to see the alternative patch.

Gemorroj and iammichiel reacted with confused emoji
@soyukasoyuka requested a review fromdunglas as acode ownerApril 27, 2020 13:22
@soyukasoyuka changed the base branch frommaster to4.4April 27, 2020 13:22
@soyukasoyukaforce-pushed thefix/serializer-preserve-empty-objects branch from05c76bb to8d2411bCompareApril 27, 2020 13:28
@soyukasoyukaforce-pushed thefix/serializer-preserve-empty-objects branch from8d2411b to1c979c0CompareApril 27, 2020 13:31
@soyukasoyukaforce-pushed thefix/serializer-preserve-empty-objects branch from1c979c0 toe5c2029CompareApril 27, 2020 14:09
@nicolas-grekasnicolas-grekas added this to the4.4 milestoneMay 1, 2020
@nicolas-grekasnicolas-grekas changed the titleFix serializer do not transform empty \Traversable to Array[Serializer] do not transform empty \Traversable to ArrayMay 1, 2020
@nicolas-grekas
Copy link
Member

Thank you@soyuka.

@nicolas-grekasnicolas-grekas merged commit4528c11 intosymfony:4.4May 1, 2020
@soyukasoyuka deleted the fix/serializer-preserve-empty-objects branchMay 4, 2020 07:11
This was referencedMay 31, 2020
@Gemorroj
Copy link
Contributor

Gemorroj commentedJun 1, 2020
edited
Loading

@nicolas-grekas
but why!? it's bc changes. Now empty doctrine collections casts to object instead of empty array

jnfry and iammichiel reacted with thumbs up emoji

@soyuka
Copy link
ContributorAuthor

but why!? it's bc changes. Now empty doctrine collections casts to object instead of empty array

You should not expose ArrayCollection but useArrayCollection->getValues instead, which will get you a real array (also fixes an index issue if you delete somthing from this ArrayCollection). ArrayCollection is an object and it's correct that it gets normalized to an object imo. Please open an issue if we should discuss this further.

@Plopix
Copy link
Contributor

@Gemorroj issue fixed ;)#37061

soyuka added a commit to api-platform/core that referenced this pull requestSep 1, 2020
* Use symfony/serializer >=4.4.9-5.0.9 to fix issuessymfony/symfony#34455symfony/symfony#36601* Lowest + legacy test suite missing git* fix Symfony 5 router generate with reference type
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@chalasrchalasrchalasr approved these changes

@dunglasdunglasdunglas approved these changes

Assignees

No one assigned

Projects

None yet

Milestone

4.4

Development

Successfully merging this pull request may close these issues.

7 participants

@soyuka@nicolas-grekas@Gemorroj@Plopix@dunglas@chalasr@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp