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] Fix access to private properties/getters when using the @Ignore annotation #52680

Merged
merged 1 commit into from Nov 24, 2023

Conversation

mtarld
Copy link
Contributor

@mtarld mtarld commented Nov 22, 2023

Q A
Branch? 5.4
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #52673 #49710
License MIT

@OskarStark OskarStark changed the title [Serializer] Fix access to private properties/getters when using the Ignore attribute [Serializer] Fix access to private properties/getters when using the @Ignore annotation Nov 22, 2023
@nesl247
Copy link

nesl247 commented Nov 22, 2023

@mtarld am I misunderstanding the documentation though? It says

All attributes are included by default when serializing objects. There are two options to ignore some of those attributes.

Which to mean means even private and protected. While I think the fix here makes sense, it doesn't align with the documentation. Should the documentation also be updated to say only publicly accessible attributes are included? Or is that what attribute means and I am missing the definition?

@stof
Copy link
Member

stof commented Nov 22, 2023

Private or protected properties are included if they have getters to access them publicly.

@nesl247
Copy link

nesl247 commented Nov 22, 2023

Private or protected properties are included if they have getters to access them publicly.

That's what I thought. Then the documentation should be updated to specify that instead of all attributes correct?

@mtarld
Copy link
Contributor Author

mtarld commented Nov 23, 2023

Indeed, we could go with something like: "All accessible attributes are included by default when serializing objects.".

WDYT? Up for a PR?

@nesl247
Copy link

nesl247 commented Nov 23, 2023

Indeed, we could go with something like: "All accessible attributes are included by default when serializing objects.".

WDYT? Up for a PR?

Yes. I’m out of the office until Tuesday, but when I get back I’m happy to submit a PR.

@nicolas-grekas
Copy link
Member

PHP Parse error: syntax error, unexpected 'string' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST) in /home/runner/work/symfony/symfony/src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php on line 498

@mtarld
Copy link
Contributor Author

mtarld commented Nov 24, 2023

Failures should be fixed in #52713

@nicolas-grekas
Copy link
Member

Thank you @mtarld.

@nicolas-grekas nicolas-grekas merged commit 1da3a5c into symfony:5.4 Nov 24, 2023
1 of 11 checks passed
@mtarld mtarld deleted the fix/ignore branch November 24, 2023 11:44
This was referenced Nov 26, 2023
OskarStark added a commit to symfony/symfony-docs that referenced this pull request Nov 28, 2023
…efault (nesl247)

This PR was submitted for the 6.4 branch but it was merged into the 5.4 branch instead.

Discussion
----------

fix: serializer includes only accessible attributes by default

Updates documentation based upon the discussion here: symfony/symfony#52680

Commits
-------

674ff7d fix: serializer includes only accessible attributes by default
nicolas-grekas added a commit that referenced this pull request Nov 29, 2023
This PR was merged into the 5.4 branch.

Discussion
----------

[Serializer] Revert allowed attributes fix

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        |
| License       | MIT

Revert #52767 and #52680, as it does not cover some specific use cases, and can't be fixed in time.

I'll attempt to fix it in a better way, taking more time.

Commits
-------

1dc20a8 [Serializer] Revert allowed attributes fix
This was referenced Nov 29, 2023
fabpot added a commit that referenced this pull request Apr 8, 2024
This PR was merged into the 5.4 branch.

Discussion
----------

[Serializer] Fix unexpected allowed attributes

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | Fix #52673 #49710
| License       | MIT

A more accurate approach than #52680

Commits
-------

900d034 [Serializer] Fix unexpected allowed attributes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants