@@ -734,7 +734,24 @@ When serializing, you can set a callback to format a specific object property::
734
734
Normalizers
735
735
-----------
736
736
737
- There are several types of normalizers available:
737
+ Normalizers turn **object ** into **array ** and vice versa. They implement
738
+ ::class: `Symfony\\ Component\\ Serializer\\ Normalizer\\ NormalizableInterface `
739
+ for normalize (object to array) and
740
+ :class: `Symfony\\ Component\\ Serializer\\ Normalizer\\ DenormalizableInterface ` for denormalize
741
+ (array to object).
742
+
743
+ You can add new normalizers to a Serializer instance by using its first constructor argument::
744
+
745
+ use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
746
+ use Symfony\Component\Serializer\Serializer;
747
+
748
+ $normalizers = [new ObjectNormalizer()];
749
+ $serializer = new Serializer($normalizers, []);
750
+
751
+ Built-in Normalizers
752
+ ~~~~~~~~~~~~~~~~~~~~
753
+
754
+ The Serializer component provides several built-in normalizers:
738
755
739
756
:class: `Symfony\\ Component\\ Serializer\\ Normalizer\\ ObjectNormalizer `
740
757
This normalizer leverages the :doc: `PropertyAccess Component </components/property_access >`
@@ -820,6 +837,14 @@ There are several types of normalizers available:
820
837
821
838
The ``UidNormalizer `` was introduced in Symfony 5.2.
822
839
840
+ .. note ::
841
+
842
+ You can also create your own Normalizer to use another structure. Read more at
843
+ :doc: `/serializer/custom_normalizer `.
844
+
845
+ All these normalizers are enabled by default when using the Serializer component
846
+ in a Symfony application.
847
+
823
848
.. _component-serializer-encoders :
824
849
825
850
Encoders
@@ -858,6 +883,11 @@ The Serializer component provides several built-in encoders:
858
883
:class: `Symfony\\ Component\\ Serializer\\ Encoder\\ CsvEncoder `
859
884
This encoder encodes and decodes data in `CSV `_.
860
885
886
+ .. note ::
887
+
888
+ You can also create your own Encoder to use another structure. Read more at
889
+ :doc: `/serializer/custom_encoders `.
890
+
861
891
All these encoders are enabled by default when using the Serializer component
862
892
in a Symfony application.
863
893
@@ -977,25 +1007,51 @@ which defines the configuration options for the XmlEncoder an associative array:
977
1007
978
1008
These are the options available:
979
1009
980
- ====================== ==================================================== ==========================
981
- Option Description Default
982
- ====================== ==================================================== ==========================
983
- ``xml_format_output `` If set to true, formats the generated XML with line
984
- breaks and indentation.
985
- ``xml_version `` Sets the XML version attribute ``1.1 ``
986
- ``xml_encoding `` Sets the XML encoding attribute ``utf-8 ``
987
- ``xml_standalone `` Adds standalone attribute in the generated XML ``true ``
988
- ``xml_root_node_name `` Sets the root node name (default: ``response ``).
989
- ``remove_empty_tags `` If set to true, removes all empty tags in the ``false ``
990
- generated XML
991
- ====================== ==================================================== ==========================
1010
+ ============================== ================================================= ==========================
1011
+ Option Description Default
1012
+ ============================== ================================================= ==========================
1013
+ ``xml_format_output `` If set to true, formats the generated XML with
1014
+ line breaks and indentation.
1015
+ ``xml_version `` Sets the XML version attribute ``1.1 ``
1016
+ ``xml_encoding `` Sets the XML encoding attribute ``utf-8 ``
1017
+ ``xml_standalone `` Adds standalone attribute in the generated XML ``true ``
1018
+ ``xml_type_cast_attributes `` This provides the ability to forgot the attribute ``true ``
1019
+ type casting
1020
+ ``xml_root_node_name `` Sets the root node name (default: ``response ``).
1021
+ ``as_collection `` Always returns results as a collection, even if
1022
+ only one line is decoded
1023
+ ``decoder_ignored_node_types `` Sets nodes to be ignored in the decode ``[\XML_PI_NODE, \XML_COMMENT_NODE] ``
1024
+ ``encoder_ignored_node_types `` Sets nodes to be ignored in the encode ``[] ``
1025
+ ``load_options `` XML loading `options with libxml `_ ``\LIBXML_NONET | \LIBXML_NOBLANKS ``
1026
+ ``remove_empty_tags `` If set to true, removes all empty tags in the ``false ``
1027
+ generated XML
1028
+ ============================== ================================================= ==========================
992
1029
993
1030
The ``YamlEncoder ``
994
1031
~~~~~~~~~~~~~~~~~~~
995
1032
996
1033
This encoder requires the :doc: `Yaml Component </components/yaml >` and
997
1034
transforms from and to Yaml.
998
1035
1036
+ The ``YamlEncoder `` Context Options
1037
+ ...................................
1038
+
1039
+ The ``encode() `` method, like other encoder, uses ``context `` to set
1040
+ configuration options for the YamlEncoder an associative array::
1041
+
1042
+ $xmlEncoder->encode($array, 'xml', $context);
1043
+
1044
+ These are the options available:
1045
+
1046
+ =============== ======================================================== ==========================
1047
+ Option Description Default
1048
+ =============== ======================================================== ==========================
1049
+ ``yaml_inline `` The level where you switch to inline YAML ``0 ``
1050
+ ``yaml_indent `` The level of indentation (used internally) ``0 ``
1051
+ ``yaml_flags `` A bit field of ``Yaml::DUMP_* `` / ``PARSE_* `` constants ``0 ``
1052
+ to customize the encoding / decoding YAML string
1053
+ =============== ======================================================== ==========================
1054
+
999
1055
Skipping ``null `` Values
1000
1056
------------------------
1001
1057
@@ -1550,6 +1606,7 @@ Learn more
1550
1606
.. _`PSR-1 standard` : https://www.php-fig.org/psr/psr-1/
1551
1607
.. _`JMS serializer` : https://github.com/schmittjoh/serializer
1552
1608
.. _RFC3339 : https://tools.ietf.org/html/rfc3339#section-5.8
1609
+ .. _`options with libxml` : https://www.php.net/manual/en/libxml.constants.php
1553
1610
.. _JSON : http://www.json.org/
1554
1611
.. _XML : https://www.w3.org/XML/
1555
1612
.. _YAML : https://yaml.org/
0 commit comments