Skip to content

Commit 2915e35

Browse files
committed
serializer: default context configuration #16010
1 parent b430be8 commit 2915e35

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

serializer.rst

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

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

180218
Using Serialization Groups Annotations

0 commit comments

Comments
 (0)