Skip to content

Navigation Menu

Sign in
Appearance settings

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

Add preserve_empty_objects support #4363

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

Conversation

Foxprodev
Copy link

@Foxprodev Foxprodev commented Jul 21, 2021

Q A
Branch? 2.6
Tickets #38192 ?
License MIT
Doc PR

CollectionNormalizer currently replacing ArrayObject with an empty array

More about main idea discussed here symfony/symfony#28363

Feel free to help me with test case and test location. Thank you 😄

@Foxprodev
Copy link
Author

Or maybe CollectionNormalizers should stop supporting empty Countables

@Foxprodev Foxprodev changed the base branch from main to 2.6 July 22, 2021 07:08
@Foxprodev Foxprodev force-pushed the preserve_empty_objects_support branch from de05be2 to b0d548a Compare July 22, 2021 07:10
@snoob
Copy link

snoob commented Jul 26, 2021

+1 for this :)

WDTY about calling the normalizer on normalizeRawCollection and fully delegate the "PRESERVE_EMPTY_OBJECTS" management to Symfony ?
Once fixed, we will be able to use this symfony/symfony#42240 on symfony 5.4

return $this->normalizer->normalize($this->normalizeRawCollection($object, $format, $context));

I have found a temporary workaround. Add "PRESERVE_EMPTY_OBJECTS" in your entity normalizationContext and declare your property as stdClass instead of array. It will be serialized as empty object instead of empty array.

@Foxprodev
Copy link
Author

Once fixed, we will be able to use this symfony/symfony#42240 on symfony 5.4

Wow this PR seems terribly bad for me. It breaks list array at all. I am currently using PRESERVE_EMPTY_OBJECTS in global context and this behaviour feels expected for me

@snoob
Copy link

snoob commented Jul 27, 2021

Wow this PR seems terribly bad for me. It breaks list array at all. I am currently using PRESERVE_EMPTY_OBJECTS in global context and this behaviour feels expected for me

About this PR, you shouldn't worry about it :) think it won't break your current behavior. You will just be able to override this for a specific property.

@Foxprodev
Copy link
Author

Foxprodev commented Jul 27, 2021

About this PR, you shouldn't worry about it :) think it won't break your current behavior. You will just be able to override this for a specific property.

According to PR ObjectNormalizer will convert all empty arrays to objects, when PRESERVE_EMPTY_OBJECTS enabled. It sounds weird for me and breaks BC.
But yes it's not about my current PR 😄

@Foxprodev
Copy link
Author

Foxprodev commented Jul 28, 2021

symfony/symfony#42240 irrelevant. Maybe I should rework this PR to support symfony/symfony#42297 in advance
All should work fine

@Foxprodev Foxprodev force-pushed the preserve_empty_objects_support branch from b0d548a to 60b38c4 Compare August 3, 2021 07:58
@Foxprodev
Copy link
Author

Added tests

@Foxprodev Foxprodev force-pushed the preserve_empty_objects_support branch 2 times, most recently from 58ade62 to fdbd75a Compare August 4, 2021 06:58
@soyuka
Copy link
Member

soyuka commented Aug 10, 2021

Could you target main?

@Foxprodev Foxprodev changed the base branch from 2.6 to main August 10, 2021 18:40
@Foxprodev Foxprodev marked this pull request as draft August 10, 2021 18:41
@Foxprodev Foxprodev force-pushed the preserve_empty_objects_support branch 2 times, most recently from 44116fd to 2235366 Compare August 10, 2021 18:49
@Foxprodev Foxprodev marked this pull request as ready for review August 10, 2021 18:49
@Foxprodev
Copy link
Author

@soyuka done

@snoob
Copy link

snoob commented Aug 10, 2021

You must rebase your branch there are conflicts

@Foxprodev Foxprodev force-pushed the preserve_empty_objects_support branch from 2235366 to a40edca Compare August 10, 2021 18:57
@snoob
Copy link

snoob commented Aug 10, 2021

Thank :)

b2p-fred added a commit to b2p-fred/core that referenced this pull request Jan 28, 2022
@alanpoulain
Copy link
Member

Superseded by #4999, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.