You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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_OBJECT
fixes#15554
Commits
-------
fac03e3 [Serializer] Add documentation about context and Serializer::EMPTY_ARRAY_AS_OBJECT
Copy file name to clipboardExpand all lines: serializer.rst
+23
Original file line number
Diff line number
Diff line change
@@ -148,6 +148,29 @@ properties and setters (``setXxx()``) to change properties:
148
148
;
149
149
};
150
150
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);
0 commit comments