Skip to content

[Serializer] improve documentation of default_context for the serializer #17305

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions reference/configuration/framework.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2752,6 +2752,9 @@ A map with default context options that will be used with each ``serialize`` and
call. This can be used for example to set the json encoding behavior by setting ``json_encode_options``
to a `json_encode flags bitmask`_.

You can inspect the :ref:`serializer context builders <serializer-using-context-builders>`
to discover the available settings.

php_errors
~~~~~~~~~~

Expand Down
7 changes: 5 additions & 2 deletions serializer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,15 @@ configuration:
serializer:
default_context:
enable_max_depth: true
yaml_indentation: 2

.. code-block:: xml

<!-- config/packages/framework.xml -->
<framework:config>
<!-- ... -->
<framework:serializer>
<default-context enable-max-depth="true"/>
<default-context enable-max-depth="true" yaml-indentation="2"/>
</framework:serializer>
</framework:config>

Expand All @@ -146,11 +147,13 @@ configuration:
// config/packages/framework.php
use Symfony\Config\FrameworkConfig;
use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer;
use Symfony\Component\Serializer\Encoder\YamlEncoder;

return static function (FrameworkConfig $framework) {
$framework->serializer()
->defaultContext([
AbstractObjectNormalizer::ENABLE_MAX_DEPTH => true
AbstractObjectNormalizer::ENABLE_MAX_DEPTH => true,
YamlEncoder::YAML_INDENTATION => 2,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is a build failure about this, but i don't understand it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any idea @Nyholm

])
;
};
Expand Down