-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Serializer] Serializing empty class without properties serializes to []
when preserve_empty_objects
is enabled
#56875
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
Labels
Comments
I have enabled the feature in the default context in the Framework: 'serializer' => [
'enabled' => true,
'name_converter' => 'serializer.name_converter.camel_case_to_snake_case',
'default_context' => [
AbstractObjectNormalizer::PRESERVE_EMPTY_OBJECTS => true,
Serializer::EMPTY_ARRAY_AS_OBJECT => true,
],
], It might be the case, that this default context is no longer used. Not sure. |
@HypeMC This does solve my issue indeed, thanks! |
@HypeMC It does solve the issue! 🎉 |
fabpot
added a commit
that referenced
this issue
Jun 15, 2024
…normalizers (HypeMC) This PR was merged into the 5.4 branch. Discussion ---------- [FrameworkBundle] Fix setting default context for certain normalizers | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #56875, fix #57316 | License | MIT Caused by #54791. The main problem is that `$context` defaults to `[]` instead of `$defaultContext`. There's a test to check this, but it didn't work when `circular_reference_handler` or `max_depth_handler` were not `null`. I also found an issue with `serializer.normalizer.property`. Since it’s not tagged with `serializer.normalizer`, which, to my understanding, is intentional, it would never have the default context bound to it. Commits ------- f903893 [FrameworkBundle] Fix setting default context for certain normalizers
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Symfony version(s) affected
7.1-RC1
Description
While testing 7.1-RC1 I noticed a change in behavior.
I have a test suite that serializes all commands (for a command bus) and confirms that they can be deserialized.
There is a command that does not have any properties:
When this is serialized with Symfony 7.0, it produces
{}
.But with Symfony 7.1-RC1 it becomes
[]
.How to reproduce
See above.
Possible Solution
While debugging the situation, I notice that in 7.0 the empty object gets normalized into ArrayObject (empty).

But on 7.1-RC1 it becomes an empty array.

Additional Context
No response
The text was updated successfully, but these errors were encountered: