File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -144,6 +144,33 @@ properties and setters (``setXxx()``) to change properties:
144144 ;
145145 };
146146
147+ Serializer Context
148+ ------------------
149+
150+ The serializer can define a context to control how the (de)serialization of
151+ resources. This context is passed to all normalizers. For example:
152+
153+ * :class: `Symfony\\ Component\\ Serializer\\ Normalizer\\ DateTimeNormalizer ` uses
154+ ``datetime_format `` key as date time format;
155+ * :class: `Symfony\\ Component\\ Serializer\\ Normalizer\\ AbstractObjectNormalizer `
156+ uses ``empty_iterable_as_object `` to represent empty objects as ``{} `` instead
157+ of ``[] `` in JSON.
158+
159+ .. versionadded :: 5.4
160+
161+ The usage of the ``empty_arrays_as_object `` option by default in the
162+ Serializer was introduced in Symfony 5.4.
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+
147174.. _serializer-using-serialization-groups-annotations :
148175
149176Using Serialization Groups Annotations
You can’t perform that action at this time.
0 commit comments