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

Commite3dff17

Browse files
committed
minor#15580 [Serializer] Add documentation about context and Serializer::EMPTY_ARRAY_AS_OBJECT (lyrixx)
This PR was squashed before being merged into the 5.4 branch.Discussion----------[Serializer] Add documentation about context and Serializer::EMPTY_ARRAY_AS_OBJECTfixes#15554Commits-------fac03e3 [Serializer] Add documentation about context and Serializer::EMPTY_ARRAY_AS_OBJECT
2 parentse80f3ce +fac03e3 commite3dff17

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

‎serializer.rst‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,29 @@ properties and setters (``setXxx()``) to change properties:
148148
;
149149
};
150150
151+
Serializer context
152+
------------------
153+
154+
The serializer can use a (de)serialization context to control how a resource is (de)serialized.
155+
The context is passed to all normalizers. For example:
156+
157+
*:class:`Symfony\\Component\\Serializer\\Normalizer\\DateTimeNormalizer` uses ``datetime_format`` key as date time format;
158+
*:class:`Symfony\\Component\\Serializer\\Normalizer\\AbstractObjectNormalizer` uses ``empty_iterable_as_object`` to preserve empty objects (keeps ``{}`` instead of ``[]`` in JSON);
159+
160+
..versionadded::5.4
161+
162+
:class:`Symfony\\Component\\Serializer\\Serializer` uses ``empty_arrays_as_object`` to serialize empty array as object (uses ``{}`` instead of ``[]`` in JSON);
163+
164+
You can pass the context like following::
165+
166+
$serializer->serialize($something, 'json', [
167+
DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s',
168+
]);
169+
170+
$serializer->deserialize($someJson, Something::class, 'json', [
171+
DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s',
172+
]);
173+
151174
.. _serializer-using-serialization-groups-annotations:
152175

153176
Using Serialization Groups Annotations

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp