Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
chalasr left a comment
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.
👍
Nyholm left a comment
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 namePRESERVE_EMPTY_OBJECTS. Im not sure it is perfect, but I don't have any suggestions Im more comfortable with.
MaybeFORCE_EMPTY_ARRAYS_AS_OBJECT.. OrEMPTY_MAP_AS_OBJECT... hm..
Did you consider anything else before deciding onPRESERVE_EMPTY_OBJECTS?
lyrixx commentedJul 25, 2021 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I did not introduce this constant. It exists for ages, with this exact purpose. 😁 |
Nyholm commentedJul 25, 2021
Oh. Sorry. You are correct. Im all 👍🏽 |
fabpot commentedJul 25, 2021
Thank you@lyrixx. |
Foxprodev commentedJul 26, 2021 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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 incd12afe
This option is even named PRESERVE notFORCE likeJSON_FORCE_OBJECTP.S. I am using api-platform and there are so much serializeable nested classes in my projects... |
lyrixx commentedJul 27, 2021
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 exampleThis 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#42297Commits-------cc54517 fix(serializer): missing empty_array_as_object in example
This PR leveragehttps://symfony.com/blog/new-in-symfony-5-3-inlined-serialization-context tofix#38192.
Example:
Will produce:
{"mapWithOption":{},"mapWithOptionAndData":{"foo":"bar"},"mapWithoutOption":[],"mapWithoutOptionAndData":{"foo":"bar"}}