Skip to content

Commit 7a175b9

Browse files
soyukawouterj
authored andcommitted
serializer: default context configuration #16010
1 parent b430be8 commit 7a175b9

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

serializer.rst

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,49 @@ You can pass the context like following::
175175
DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s',
176176
]);
177177

178+
You can also configure the default context through the framework
179+
configuration:
180+
181+
.. configuration-block::
182+
183+
.. code-block:: yaml
184+
185+
# config/packages/framework.yaml
186+
framework:
187+
# ...
188+
serializer:
189+
default_context:
190+
enable_max_depth: true
191+
192+
.. code-block:: xml
193+
194+
<!-- config/packages/framework.xml -->
195+
<framework:config>
196+
<!-- ... -->
197+
<framework:serializer>
198+
<default-context enable-max-depth="true"/>
199+
</framework:serializer>
200+
</framework:config>
201+
202+
.. code-block:: php
203+
204+
// config/packages/framework.php
205+
use Symfony\Config\FrameworkConfig;
206+
use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer;
207+
208+
return static function (FrameworkConfig $framework) {
209+
$framework->serializer()
210+
->defaultContext([
211+
AbstractObjectNormalizer::ENABLE_MAX_DEPTH => true
212+
])
213+
;
214+
};
215+
216+
.. versionadded:: 5.4
217+
218+
The ability to configure the ``default_context`` option in the
219+
Serializer was introduced in Symfony 5.4.
220+
178221
.. _serializer-using-serialization-groups-annotations:
179222

180223
Using Serialization Groups Annotations

0 commit comments

Comments
 (0)