Skip to content

[Serializer] All fields are not included by default, but upon adding any attribute, all fields are then required #52673

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

Closed
nesl247 opened this issue Nov 21, 2023 · 1 comment

Comments

@nesl247
Copy link

nesl247 commented Nov 21, 2023

Symfony version(s) affected

6.3.8

Description

According to https://symfony.com/doc/current/components/serializer.html#ignoring-attributes all properties are included by default, which makes sense. However, this doesn't seem to be the case at least for traits and abstract classes.

When we don't add the #[Ignore] attribute in the TestTrait in the reproducer, everything works fine. However, adding that attribute causes all of the other properties to now be seen by the serializer and then fail because there is no public access to them via getters or via public properties.

How to reproduce

https://github.com/nesl247/symfony-serialization-ignore-bug

  1. git clone https://github.com/nesl247/symfony-serialization-ignore-bug.git
  2. composer install
  3. bin/console test:command

Possible Solution

No response

Additional Context


In PropertyAccessor.php line 456:
                                                                                    
  Can't get a way to read the property "testProperty2" in class "App\TestMessage".  
                                                                                    
@mtarld
Copy link
Contributor

mtarld commented Nov 22, 2023

Seems like it is related to #49710

nicolas-grekas added a commit that referenced this issue Nov 24, 2023
… using the ``@Ignore`` annotation (mtarld)

This PR was merged into the 5.4 branch.

Discussion
----------

[Serializer] Fix access to private properties/getters when using the ``@Ignore`` annotation

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

Commits
-------

cc356b0 [Serializer] Fix access to private when Ignore
@xabbuh xabbuh reopened this Nov 29, 2023
@fabpot fabpot closed this as completed Apr 8, 2024
fabpot added a commit that referenced this issue 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

No branches or pull requests

6 participants