@@ -789,13 +789,13 @@ When serializing, you can set a callback to format a specific object property::
789
789
Normalizers
790
790
-----------
791
791
792
- Normalizers turn **object ** into **array ** and vice versa. They implement
793
- :class: `Symfony\\ Component\\ Serializer\\ Normalizer\\ NormalizableInterface `
794
- for normalize (object to array) and
795
- :class: `Symfony\\ Component\\ Serializer\\ Normalizer\\ DenormalizableInterface ` for denormalize
796
- (array to object).
792
+ Normalizers turn **objects ** into **arrays ** and vice versa. They implement
793
+ :class: `Symfony\\ Component\\ Serializer\\ Normalizer\\ NormalizerInterface ` for
794
+ normalizing (object to array) and
795
+ :class: `Symfony\\ Component\\ Serializer\\ Normalizer\\ DenormalizerInterface ` for
796
+ denormalizing (array to object).
797
797
798
- You can add new normalizers to a Serializer instance by using its first constructor argument::
798
+ Normalizers are enabled in the serializer passing them as its first argument::
799
799
800
800
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
801
801
use Symfony\Component\Serializer\Serializer;
@@ -900,6 +900,56 @@ The Serializer component provides several built-in normalizers:
900
900
Also it can denormalize ``uuid `` or ``ulid `` strings to :class: `Symfony\\ Component\\ Uid\\ Uuid `
901
901
or :class: `Symfony\\ Component\\ Uid\\ Ulid `. The format does not matter.
902
902
903
+ Certain normalizers are enabled by default when using the Serializer component
904
+ in a Symfony application, additional ones can be enabled by tagging them with
905
+ :ref: `serializer.normalizer <reference-dic-tags-serializer-normalizer >`.
906
+
907
+ Here is an example of how to enable the built-in
908
+ :class: `Symfony\\ Component\\ Serializer\\ Normalizer\\ GetSetMethodNormalizer `, a
909
+ faster alternative to the
910
+ :class: `Symfony\\ Component\\ Serializer\\ Normalizer\\ ObjectNormalizer `:
911
+
912
+ .. configuration-block ::
913
+
914
+ .. code-block :: yaml
915
+
916
+ # config/services.yaml
917
+ services :
918
+ get_set_method_normalizer :
919
+ class : Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer
920
+ tags : [serializer.normalizer]
921
+
922
+ .. code-block :: xml
923
+
924
+ <!-- config/services.xml -->
925
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
926
+ <container xmlns =" http://symfony.com/schema/dic/services"
927
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
928
+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
929
+ https://symfony.com/schema/dic/services/services-1.0.xsd" >
930
+
931
+ <services >
932
+ <service id =" get_set_method_normalizer" class =" Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer" >
933
+ <tag name =" serializer.normalizer" />
934
+ </service >
935
+ </services >
936
+ </container >
937
+
938
+ .. code-block :: php
939
+
940
+ // config/services.php
941
+ namespace Symfony\Component\DependencyInjection\Loader\Configurator;
942
+
943
+ use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer;
944
+
945
+ return function(ContainerConfigurator $configurator) {
946
+ $services = $configurator->services();
947
+
948
+ $services->set('get_set_method_normalizer', GetSetMethodNormalizer::class)
949
+ ->tag('serializer.normalizer')
950
+ ;
951
+ };
952
+
903
953
.. _component-serializer-encoders :
904
954
905
955
Encoders
0 commit comments