Skip to content
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] MetadataAwareNameConverter break groups parameters #34455

Closed
gilles-g opened this issue Nov 19, 2019 · 2 comments
Closed

[Serializer] MetadataAwareNameConverter break groups parameters #34455

gilles-g opened this issue Nov 19, 2019 · 2 comments

Comments

@gilles-g
Copy link

gilles-g commented Nov 19, 2019

Symfony version(s) affected: 4.3.7

Description
Since #34035, cannot denormalize with that syntax ['groups' => 'user']

How to reproduce

$obj = $normalizer->denormalize(['bar' => 'Api Platform'], Foo::class, null, ['groups' => 'user']);

-->

/**
In MetadataAwareNameConverter.php line 126:
                                                                                 
Warning: array_intersect(): Expected parameter 2 to be an array, string given
*/

https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Serializer/NameConverter/MetadataAwareNameConverter.php#L126

Possible Solution

@antograssiot If you could have a look at this

Additional context

@bizley
Copy link

bizley commented Nov 19, 2019

I can confirm the same problem. Changing the groups value to array helped. Possible solution is the array cast in this line:

if ($groups && !array_intersect($groups, (array)$context[AbstractNormalizer::GROUPS] ?? [])) {

@antograssiot
Copy link
Contributor

I just submitted a fix, apologies for that 😞

nicolas-grekas added a commit that referenced this issue Nov 28, 2019
…ing group (antograssiot)

This PR was merged into the 4.3 branch.

Discussion
----------

[Serializer] Fix MetadataAwareNameConverter usage with string group

| Q             | A
| ------------- | ---
| Branch?       | 4.3
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #34455
| License       | MIT
| Doc PR        |

Allow to use the short syntax for serialization context group like `['groups' => 'user']`

Commits
-------

d4f749a [Serializer] Fix MetadataAwareNameConverter usage with string group
soyuka added a commit to soyuka/core that referenced this issue Aug 31, 2020
soyuka added a commit to soyuka/core that referenced this issue Aug 31, 2020
soyuka added a commit to api-platform/core that referenced this issue Sep 1, 2020
* Use symfony/serializer >=4.4.9-5.0.9 to fix issues

symfony/symfony#34455
symfony/symfony#36601

* Lowest + legacy test suite missing git

* fix Symfony 5 router generate with reference type
hultberg pushed a commit to hultberg/symfony that referenced this issue Sep 17, 2021
…ith string group (antograssiot)

This PR was merged into the 4.3 branch.

Discussion
----------

[Serializer] Fix MetadataAwareNameConverter usage with string group

| Q             | A
| ------------- | ---
| Branch?       | 4.3
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix symfony#34455
| License       | MIT
| Doc PR        |

Allow to use the short syntax for serialization context group like `['groups' => 'user']`

Commits
-------

d4f749a [Serializer] Fix MetadataAwareNameConverter usage with string group
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants