-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Serializer] Add support for preserving empty object in object property #42240
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I read the PR title and I was mentally preparing for reviewing a 500+ lines PR of complicated Serializer code.
This looks great. Well done.
Maybe we should take a short moment to discuss the name PRESERVE_EMPTY_OBJECTS
. Im not sure it is perfect, but I don't have any suggestions Im more comfortable with.
Maybe FORCE_EMPTY_ARRAYS_AS_OBJECT
.. Or EMPTY_MAP_AS_OBJECT
... hm..
Did you consider anything else before deciding on PRESERVE_EMPTY_OBJECTS
?
I did not introduce this constant. It exists for ages, with this exact purpose. 😁 |
Oh. Sorry. You are correct. Im all 👍🏽 |
Thank you @lyrixx. |
Well. It's weird, starting from 5.4 I have to move from
to
Is it an expected complication? @lyrixx @chalasr @Nyholm symfony/src/Symfony/Component/Serializer/Serializer.php Lines 161 to 164 in cd12afe
This option is even named PRESERVE not FORCE like JSON_FORCE_OBJECT
P.S. I am using api-platform and there are so much serializeable nested classes in my projects... |
I'll answer in the issue. |
…ect in example (alanpoulain) This PR was merged into the 5.4 branch. Discussion ---------- [Serializer] fix(serializer): missing empty_array_as_object in example This PR: - Replaces `empty_iterable_as_object` by `preserve_empty_objects`, like it should be. - Adds `empty_array_as_object` to example in Serializer Context. - Removes the mention `by default`, since it's `false` by default. Related: - #15554 - #15580 - symfony/symfony#42240 - symfony/symfony#42297 Commits ------- cc54517 fix(serializer): missing empty_array_as_object in example
This PR leverage https://symfony.com/blog/new-in-symfony-5-3-inlined-serialization-context to fix #38192.
Example:
Will produce: