Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitabc5d28

Browse files
committed
minor#20877 [Serializer] (re)document PRESERVE_EMPTY_OBJECTS (94noni)
This PR was submitted for the 7.2 branch but it was squashed and merged into the 6.4 branch instead.Discussion----------[Serializer] (re)document PRESERVE_EMPTY_OBJECTS👋🏻when implementing a web hook, I had to serialize en empty array as object, and found it was wrong (empty list not empty object)```php// json without flag'data' => [],"data":[],// json with flag'data' => new \ArrayObject(),"data":{},```this PR (re)adds this feature as I thinks its useful to have it directly showcased in the main docweirdly it was present in v5.4#16977Commits-------ce28629 [Serializer] (re)document PRESERVE_EMPTY_OBJECTS
2 parentsccd1137 +ce28629 commitabc5d28

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

‎serializer.rst‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,6 +1571,13 @@ to ``true``::
15711571
]);
15721572
// $jsonContent contains {"name":"Jane Doe"}
15731573

1574+
Preserving Empty Objetcs
1575+
~~~~~~~~~~~~~~~~~~~~~~~~
1576+
1577+
By default, the Serializer will transform an empty array to `[]`.
1578+
You can change this behavior by setting the ``AbstractObjectNormalizer::PRESERVE_EMPTY_OBJECTS`` context option
1579+
to ``true``, when the value is `\ArrayObject()` the serialization would be `{}`.
1580+
15741581
Handling Uninitialized Properties
15751582
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15761583

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp