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

Nested groups should apply to hashes too #1385

Open
Uplink03 opened this issue Jan 2, 2022 · 0 comments
Open

Nested groups should apply to hashes too #1385

Uplink03 opened this issue Jan 2, 2022 · 0 comments

Comments

@Uplink03
Copy link

Uplink03 commented Jan 2, 2022

Q A
Bug report? maybe
Feature request? maybe
BC Break report? no
RFC? no

Steps required to reproduce the problem

$x = [
    'a' => [objects],
    'b' => [objects],
];

$context = SerializerContext::create()->setGroups([
    'group1',
    'b' => [
        'group2',
    ],
]);

Expected Result

  • When serializing the hash, I expected to have 'group2' apply to the objects under the 'b' key.

Actual Result

  • The nested group for 'b' has no effect.

As far as I can tell from browsing the source code, there's no easy fix. Hashes would have to be visited in a similar manner as to objects, which currently isn't the case.

I tried to work around with:

  • an anonymous class (this crashes hard in some ORM code)
  • stdClass with dynamic members (this resulted in an empty JSON object)

For now I resorted to creating a class with all the required members defined on it, but it's a bit of overkill for this use case.

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

2 participants