Skip to content

[Serializer] Add support for preserving empty object in object property #15554

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
fabpot opened this issue Jul 25, 2021 · 0 comments · Fixed by #15580
Closed

[Serializer] Add support for preserving empty object in object property #15554

fabpot opened this issue Jul 25, 2021 · 0 comments · Fixed by #15580
Milestone

Comments

@fabpot
Copy link
Member

fabpot commented Jul 25, 2021

Q A
Feature PR symfony/symfony#42240
PR author(s) @lyrixx
Merged in 5.4
@fabpot fabpot added this to the 5.4 milestone Jul 25, 2021
fabpot added a commit to symfony/symfony that referenced this issue Jul 30, 2021
…s object (lyrixx)

This PR was merged into the 5.4 branch.

Discussion
----------

[Serializer] Add support for serializing empty array as object

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes (fix a new feature)
| New feature?  | yes (fix a new feature)
| Deprecations? | no
| Tickets       | Fix #42282
| License       | MIT
| Doc PR        | symfony/symfony-docs#15554

---

New usage:

```php
    public function __construct(
        #[Context([Serializer::EMPTY_ARRAY_AS_OBJECT => true ])]
        public array $mapWithOption = [],
        #[Context([Serializer::EMPTY_ARRAY_AS_OBJECT => true ])]
        public array $mapWithOptionAndData = ['foo' => 'bar'],
        public array $mapWithoutOption = [],
        public array $mapWithoutOptionAndData = ['foo' => 'bar'],
    ) {
    }
```
=>
```
{"mapWithOption":{},"mapWithOptionAndData":{"foo":"bar"},"mapWithoutOption":[],"mapWithoutOptionAndData":{"foo":"bar"}}
```

Commits
-------

c940b74 [Serializer] Add support for serializing empty array as object
javiereguiluz added a commit that referenced this issue Aug 8, 2022
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants