Skip to content

[Serializer] Update serializer.rst #16912

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

Merged
merged 1 commit into from
Oct 4, 2022
Merged

Conversation

sfmok
Copy link
Contributor

@sfmok sfmok commented Jun 24, 2022

I have checked ObjectNormalizer and I found only methods start by (is, has, get, and can) can be detected automatically for normalising them

Am I wrong?

@carsonbot carsonbot added this to the 6.2 milestone Jun 24, 2022
@javiereguiluz
Copy link
Member

In the PropertyInfo component I can find references to add and remove:

https://github.com/symfony/symfony/blob/4a31363c3c9be2192e757c3a32a7e3a90874a2cb/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php#L38-L48

But in the Serializer component I can't find any references to them. This is what I see:

https://github.com/symfony/symfony/blob/4a31363c3c9be2192e757c3a32a7e3a90874a2cb/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php#L128-L148

@ostrolucky
Copy link
Contributor

OP probably looks at it from POV of normalization only and is forgetting about denormalization.

@ndench
Copy link
Contributor

ndench commented Jul 11, 2022

Object normalization/denoramilzation definitely takes into account adders/removers for array properties. As @javiereguiluz points out, when denormalizing it uses the PropertyInfo component to set the value of an array property. If there is not a function setFoos(array $foos) then it'll look for function addFoo($foo) and function removeFoo($foo).

However, the section that OP is editing is specifically to do with boolean attributes. I would imagine that adders/removers are not considered for boolean properties, however I am not certain of this.

@FabienPapet
Copy link
Contributor

ping @mtarld

@mtarld
Copy link
Contributor

mtarld commented Jul 12, 2022

Indeed, as @javiereguiluz and @ndench pointed out, the PropertyInfo can find add and remove methods (therefore the ObjectNormalizer can), but the add and remove methods are related to collections and not boolean.

So I think it doesn't make sense to mention them here.
Moreover, IMHO, I'm not sure that we must mention the get method even if it can return a boolean as it's not specific to booleans only (you can have a look at the ReflectionExtractor)

@sfmok
Copy link
Contributor Author

sfmok commented Jul 17, 2022

Thank you all for the clarification.

In fact, I assumed the edited part is talking about booleans attributes based on the first phrase context is about the is method.

I think we can adjust it somehow to be more clear like:

The ObjectNormalizer also takes care of methods starting with :

  • has and can for booleans attributes.
  • add and remove for collections

for get method, I avoided adding it into the list since it's not specific to booleans as @mtarld mentioned

@carsonbot carsonbot changed the title Update serializer.rst [Serializer] Update serializer.rst Jul 22, 2022
@wouterj wouterj modified the milestones: 6.2, 4.4 Sep 20, 2022
I have checked  ``ObjectNormalizer`` and I found only methods start by (has,  get,  and  can) can be detected automatically for normalising them

Am I wrong?
@javiereguiluz
Copy link
Member

Thank you @sfmok.

@javiereguiluz javiereguiluz merged commit 428f2f0 into symfony:4.4 Oct 4, 2022
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.

9 participants