Skip to content

Commit bffad6d

Browse files
committed
Minor tweaks
1 parent bec0676 commit bffad6d

File tree

1 file changed

+30
-31
lines changed

1 file changed

+30
-31
lines changed

serializer.rst

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,13 +1544,13 @@ Named Serializers
15441544

15451545
Named serializers were introduced in Symfony 7.2.
15461546

1547-
Sometimes, you may need multiple configurations for the serializer, such
1548-
as different default contexts, name converters, or sets of normalizers and
1549-
encoders, depending on the use case. For example, when your application
1550-
communicates with multiple APIs, each with its own set of rules.
1547+
Sometimes, you may need multiple configurations for the serializer, such as
1548+
different default contexts, name converters, or sets of normalizers and encoders,
1549+
depending on the use case. For example, when your application communicates with
1550+
multiple APIs, each of which follows its own set of serialization rules.
15511551

1552-
This can be achieved by configuring multiple instances of the serializer
1553-
using the ``named_serializers`` option:
1552+
You can achieve this by configuring multiple serializer instances using
1553+
the ``named_serializers`` option:
15541554

15551555
.. configuration-block::
15561556

@@ -1633,7 +1633,7 @@ using :ref:`named aliases <autowiring-multiple-implementations-same-type>`::
16331633
class PersonController extends AbstractController
16341634
{
16351635
public function index(
1636-
SerializerInterface $serializer, // Default serializer
1636+
SerializerInterface $serializer, // default serializer
16371637
SerializerInterface $apiClient1Serializer, // api_client1 serializer
16381638
#[Target('apiClient2.serializer')] // api_client2 serializer
16391639
SerializerInterface $customName,
@@ -1642,10 +1642,10 @@ using :ref:`named aliases <autowiring-multiple-implementations-same-type>`::
16421642
}
16431643
}
16441644

1645-
Named serializers are configured with the default set of normalizers and encoders.
1646-
1647-
You can register additional normalizers and encoders with a specific named
1648-
serializer by adding a ``serializer`` attribute to
1645+
By default, named serializers use the built-in set of normalizers and encoders,
1646+
just like the main serializer service. However, you can customize them by
1647+
registering additional normalizers or encoders for a specific named serializer.
1648+
To do that, add a ``serializer`` attribute to
16491649
the :ref:`serializer.normalizer <reference-dic-tags-serializer-normalizer>`
16501650
or :ref:`serializer.encoder <reference-dic-tags-serializer-encoder>` tags:
16511651

@@ -1658,14 +1658,14 @@ or :ref:`serializer.encoder <reference-dic-tags-serializer-encoder>` tags:
16581658
# ...
16591659
16601660
Symfony\Component\Serializer\Normalizer\CustomNormalizer:
1661-
# Prevent this normalizer from automatically being included in the default serializer
1661+
# prevent this normalizer from being automatically added to the default serializer
16621662
autoconfigure: false
16631663
tags:
1664-
# Include this normalizer in a single serializer
1664+
# add this normalizer only to a specific named serializer
16651665
- serializer.normalizer: { serializer: 'api_client1' }
1666-
# Include this normalizer in multiple serializers
1666+
# add this normalizer to several named serializers
16671667
- serializer.normalizer: { serializer: [ 'api_client1', 'api_client2' ] }
1668-
# Include this normalizer in all serializers (including the default one)
1668+
# add this normalizer to all serializers, including the default one
16691669
- serializer.normalizer: { serializer: '*' }
16701670
16711671
.. code-block:: xml
@@ -1680,20 +1680,19 @@ or :ref:`serializer.encoder <reference-dic-tags-serializer-encoder>` tags:
16801680
<services>
16811681
<!-- ... -->
16821682
1683-
<!-- Disable autoconfigure to prevent this normalizer from automatically -->
1684-
<!-- being included in the default serializer -->
1683+
<!-- prevent this normalizer from being automatically added to the default serializer -->
16851684
<service
16861685
id="Symfony\Component\Serializer\Normalizer\CustomNormalizer"
16871686
autoconfigure="false"
16881687
>
1689-
<!-- Include this normalizer in a single serializer -->
1688+
<!-- add this normalizer only to a specific named serializer -->
16901689
<tag name="serializer.normalizer" serializer="api_client1"/>
16911690
1692-
<!-- Include this normalizer in multiple serializers -->
1691+
<!-- add this normalizer to several named serializers -->
16931692
<tag name="serializer.normalizer" serializer="api_client1"/>
16941693
<tag name="serializer.normalizer" serializer="api_client2"/>
16951694
1696-
<!-- Include this normalizer in all serializers (including the default one) -->
1695+
<!-- add this normalizer to all serializers, including the default one -->
16971696
<tag name="serializer.normalizer" serializer="*"/>
16981697
</service>
16991698
</services>
@@ -1710,32 +1709,32 @@ or :ref:`serializer.encoder <reference-dic-tags-serializer-encoder>` tags:
17101709
// ...
17111710
17121711
$services->set(CustomNormalizer::class)
1713-
// Prevent this normalizer from automatically being included in the default serializer
1712+
// prevent this normalizer from being automatically added to the default serializer
17141713
->autoconfigure(false)
17151714
1716-
// Include this normalizer in a single serializer
1715+
// add this normalizer only to a specific named serializer
17171716
->tag('serializer.normalizer', ['serializer' => 'api_client1'])
1718-
// Include this normalizer in multiple serializers
1717+
// add this normalizer to several named serializers
17191718
->tag('serializer.normalizer', ['serializer' => ['api_client1', 'api_client2']])
1720-
// Include this normalizer in all serializers (including the default one)
1719+
// add this normalizer to all serializers, including the default one
17211720
->tag('serializer.normalizer', ['serializer' => '*'])
17221721
;
17231722
};
17241723
1725-
When the ``serializer`` attribute is not set, the service is registered with
1724+
When the ``serializer`` attribute is not set, the service is registered only with
17261725
the default serializer.
17271726

1728-
Each normalizer and encoder used in a named serializer is tagged with
1729-
a ``serializer.normalizer.<name>`` or ``serializer.encoder.<name>`` tag,
1730-
which can be used to list their priorities using the following command:
1727+
Each normalizer or encoder used in a named serializer is tagged with a
1728+
``serializer.normalizer.<name>`` or ``serializer.encoder.<name>`` tag.
1729+
You can inspect their priorities using the following command:
17311730

17321731
.. code-block:: terminal
17331732
17341733
$ php bin/console debug:container --tag serializer.<normalizer|encoder>.<name>
17351734
1736-
Additionally, you can exclude the default set of normalizers and encoders by
1737-
setting the ``include_built_in_normalizers`` and ``include_built_in_encoders``
1738-
options to ``false``:
1735+
Additionally, you can exclude the default set of normalizers and encoders from a
1736+
named serializer by setting the ``include_built_in_normalizers`` and
1737+
``include_built_in_encoders`` options to ``false``:
17391738

17401739
.. configuration-block::
17411740

0 commit comments

Comments
 (0)