Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Serializer] Allow (de)normalization of empty objects in PropertyNormalizer #46417

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

Open
wants to merge 2 commits into
base: 7.3
Choose a base branch
Loading
from

Conversation

olsavmic
Copy link
Contributor

@olsavmic olsavmic commented May 20, 2022

Q A
Branch? 6.2
Bug fix? no
New feature? yes
Deprecations? no
Tickets Fix #46280 (comment)
License MIT
Doc PR symfony/symfony-docs#...

This PR adds optional support for the normalization of objects without properties (in the case of PropertyNormalizer) or objects without getters (in the case of GetSetMethodNormalizer). Backward compatibility is preserved since this change is disabled by default for now.

Reasoning behind this change is explained in the discussion of the linked issue (#46280)

@olsavmic olsavmic requested a review from dunglas as a code owner May 20, 2022 15:25
@carsonbot carsonbot added this to the 6.2 milestone May 20, 2022
@olsavmic olsavmic changed the base branch from 6.2 to 6.1 May 20, 2022 15:28
@olsavmic olsavmic changed the title [Serializer] Allow (de)normalization of empty objects in PropertyNorm… WIP: [Serializer] Allow (de)normalization of empty objects in PropertyNorm… May 20, 2022
@carsonbot
Copy link

Hey!

I think @mtarld has recently worked with this code. Maybe they can help review this?

Cheers!

Carsonbot

@olsavmic olsavmic changed the title WIP: [Serializer] Allow (de)normalization of empty objects in PropertyNorm… [Serializer] Allow (de)normalization of empty objects in PropertyNorm… May 23, 2022
@olsavmic olsavmic force-pushed the olsavmic-property-normalizer-allow-empty-object branch from 4989076 to b80705a Compare May 23, 2022 11:19
@olsavmic
Copy link
Contributor Author

@mtarld The original issue is marked as Bug, should I target 4.x release or 6.1? I'd say it's rather a feature.

Also, I don't see any documentation for normalizers except for https://symfony.com/doc/5.2/serializer/normalizers.html#built-in-normalizers, I guess it's self-documented enough.

And lastly, I'm still wondering if the backward compatible behavior is needed in this edge case. Or at least what about adding a deprecation notice in case the original check does not pass so that we can delete it in a subsequent version? I mean I don't mind and most people configuring their normalizers can probably find this configuration option but it would prevent the unexpected first encounter of this feature 😄

@mtarld
Copy link
Contributor

mtarld commented May 23, 2022

Yes indeed, IMO it must be a feature 🙂

I guess the documentation, code, and context builders are enough.

For the BC migration path part, it is tricky. The behavior of these normalizers is changed (and the same goes for the serializer itself), so we must trigger a deprecation IMHO.

Maybe we could leverage the func_num_args function as it does not count the optional args that aren't explicitly given. This will hopefully work as the allowNormalizationOfObjectsWithoutXXX is the last property.
Something like if (func_num_args() < 6) then trigger a deprecation that tells the user to explicitly give the allowNormalizationOfObjectsWithoutXXX as it'll default to true in the 7.0 release.

WDYT?

@olsavmic olsavmic force-pushed the olsavmic-property-normalizer-allow-empty-object branch from b80705a to 14f5c30 Compare May 23, 2022 17:29
@olsavmic
Copy link
Contributor Author

olsavmic commented May 23, 2022

Sounds good, I've added the deprecation, updated the default symfony bundle configuration (src/Symfony/Bundle/FrameworkBundle/Resources/config/serializer.php) and updated tests so that the deprecation is not triggered :)

Do we want to target 6.1 or 6.2 release?

@olsavmic olsavmic force-pushed the olsavmic-property-normalizer-allow-empty-object branch from 38a3438 to ca505aa Compare May 23, 2022 17:59
@mtarld
Copy link
Contributor

mtarld commented May 23, 2022

As 6.1 is in feature freeze, we must target 6.2

Copy link
Contributor

@mtarld mtarld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost good for me! 🙂

@olsavmic olsavmic force-pushed the olsavmic-property-normalizer-allow-empty-object branch from 2d0f77f to d7114f0 Compare May 27, 2022 17:13
@olsavmic olsavmic requested a review from yceruto as a code owner May 27, 2022 17:13
@olsavmic olsavmic changed the base branch from 6.1 to 6.2 May 27, 2022 17:14
@olsavmic olsavmic force-pushed the olsavmic-property-normalizer-allow-empty-object branch 2 times, most recently from 72c0c98 to 02a8212 Compare May 27, 2022 17:25
@OskarStark OskarStark changed the title [Serializer] Allow (de)normalization of empty objects in PropertyNorm… [Serializer] Allow (de)normalization of empty objects in PropertyNormalizer May 29, 2022
Copy link
Contributor

@mtarld mtarld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@olsavmic olsavmic force-pushed the olsavmic-property-normalizer-allow-empty-object branch from 648b0d4 to 9de526d Compare August 8, 2022 16:27
@olsavmic
Copy link
Contributor Author

olsavmic commented Aug 8, 2022

Failing checks seem to be unrelated

@nicolas-grekas nicolas-grekas modified the milestones: 6.2, 6.3 Nov 5, 2022
@olsavmic
Copy link
Contributor Author

Anything I can do to get a second review and merge it?

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.

Symfony\Component\Serializer\Normalizer\PropertyNormalizer is unable to construct object without properties
6 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.