@@ -691,7 +691,24 @@ When serializing, you can set a callback to format a specific object property::
691
691
Normalizers
692
692
-----------
693
693
694
- There are several types of normalizers available:
694
+ Normalizers turn **object ** into **array ** and vice versa. They implement
695
+ ::class: `Symfony\\ Component\\ Serializer\\ Normalizer\\ NormalizableInterface `
696
+ for normalize (object to array) and
697
+ :class: `Symfony\\ Component\\ Serializer\\ Normalizer\\ DenormalizableInterface ` for denormalize
698
+ (array to object).
699
+
700
+ You can add new normalizers to a Serializer instance by using its first constructor argument::
701
+
702
+ use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
703
+ use Symfony\Component\Serializer\Serializer;
704
+
705
+ $normalizers = [new ObjectNormalizer()];
706
+ $serializer = new Serializer($normalizers, []);
707
+
708
+ Built-in Normalizers
709
+ ~~~~~~~~~~~~~~~~~~~~
710
+
711
+ The Serializer component provides several built-in normalizers:
695
712
696
713
:class: `Symfony\\ Component\\ Serializer\\ Normalizer\\ ObjectNormalizer `
697
714
This normalizer leverages the :doc: `PropertyAccess Component </components/property_access >`
@@ -765,6 +782,14 @@ There are several types of normalizers available:
765
782
:class: `Symfony\\ Component\\ Serializer\\ Normalizer\\ ProblemNormalizer `
766
783
Normalizes errors according to the API Problem spec `RFC 7807 `_.
767
784
785
+ .. note ::
786
+
787
+ You can also create your own Normalizer to use another structure. Read more at
788
+ :doc: `/serializer/custom_normalizer `.
789
+
790
+ All these normalizers are enabled by default when using the Serializer component
791
+ in a Symfony application.
792
+
768
793
.. _component-serializer-encoders :
769
794
770
795
Encoders
@@ -803,6 +828,11 @@ The Serializer component provides several built-in encoders:
803
828
:class: `Symfony\\ Component\\ Serializer\\ Encoder\\ CsvEncoder `
804
829
This encoder encodes and decodes data in `CSV `_.
805
830
831
+ .. note ::
832
+
833
+ You can also create your own Encoder to use another structure. Read more at
834
+ :doc: `/serializer/custom_encoders `.
835
+
806
836
All these encoders are enabled by default when using the Serializer component
807
837
in a Symfony application.
808
838
@@ -927,25 +957,55 @@ which defines the configuration options for the XmlEncoder an associative array:
927
957
928
958
These are the options available:
929
959
930
- ====================== ==================================================== ==========================
931
- Option Description Default
932
- ====================== ==================================================== ==========================
933
- ``xml_format_output `` If set to true, formats the generated XML with line
934
- breaks and indentation.
935
- ``xml_version `` Sets the XML version attribute ``1.1 ``
936
- ``xml_encoding `` Sets the XML encoding attribute ``utf-8 ``
937
- ``xml_standalone `` Adds standalone attribute in the generated XML ``true ``
938
- ``xml_root_node_name `` Sets the root node name (default: ``response ``).
939
- ``remove_empty_tags `` If set to true, removes all empty tags in the ``false ``
940
- generated XML
941
- ====================== ==================================================== ==========================
960
+ ============================== ================================================= ==========================
961
+ Option Description Default
962
+ ============================== ================================================= ==========================
963
+ ``xml_format_output `` If set to true, formats the generated XML with
964
+ line breaks and indentation.
965
+ ``xml_version `` Sets the XML version attribute ``1.1 ``
966
+ ``xml_encoding `` Sets the XML encoding attribute ``utf-8 ``
967
+ ``xml_standalone `` Adds standalone attribute in the generated XML ``true ``
968
+ ``xml_type_cast_attributes `` This provides the ability to forgot the attribute ``true ``
969
+ type casting
970
+ ``xml_root_node_name `` Sets the root node name (default: ``response ``).
971
+ ``as_collection `` Always returns results as a collection, even if
972
+ only one line is decoded
973
+ ``decoder_ignored_node_types `` Sets nodes to be ignored in the decode ``[\XML_PI_NODE, \XML_COMMENT_NODE] ``
974
+ ``encoder_ignored_node_types `` Sets nodes to be ignored in the encode ``[] ``
975
+ ``load_options `` XML loading `options with libxml `_ ``\LIBXML_NONET | \LIBXML_NOBLANKS ``
976
+ ``remove_empty_tags `` If set to true, removes all empty tags in the ``false ``
977
+ generated XML
978
+ ============================== ================================================= ==========================
979
+
980
+ .. versionadded :: 4.2
981
+
982
+ The ``decoder_ignored_node_types `` & ``encoder_ignored_node_types `` options was introduced in Symfony 4.2.
942
983
943
984
The ``YamlEncoder ``
944
985
~~~~~~~~~~~~~~~~~~~
945
986
946
987
This encoder requires the :doc: `Yaml Component </components/yaml >` and
947
988
transforms from and to Yaml.
948
989
990
+ The ``YamlEncoder `` Context Options
991
+ ...................................
992
+
993
+ The ``encode() `` method, like other encoder, uses ``context `` to set
994
+ configuration options for the YamlEncoder an associative array::
995
+
996
+ $xmlEncoder->encode($array, 'xml', $context);
997
+
998
+ These are the options available:
999
+
1000
+ =============== ======================================================== ==========================
1001
+ Option Description Default
1002
+ =============== ======================================================== ==========================
1003
+ ``yaml_inline `` The level where you switch to inline YAML ``0 ``
1004
+ ``yaml_indent `` The level of indentation (used internally) ``0 ``
1005
+ ``yaml_flags `` A bit field of ``Yaml::DUMP_* `` / ``PARSE_* `` constants ``0 ``
1006
+ to customize the encoding / decoding YAML string
1007
+ =============== ======================================================== ==========================
1008
+
949
1009
Skipping ``null `` Values
950
1010
------------------------
951
1011
@@ -1512,6 +1572,7 @@ Learn more
1512
1572
.. _`PSR-1 standard` : https://www.php-fig.org/psr/psr-1/
1513
1573
.. _`JMS serializer` : https://github.com/schmittjoh/serializer
1514
1574
.. _RFC3339 : https://tools.ietf.org/html/rfc3339#section-5.8
1575
+ .. _`options with libxml` : https://www.php.net/manual/en/libxml.constants.php
1515
1576
.. _JSON : http://www.json.org/
1516
1577
.. _XML : https://www.w3.org/XML/
1517
1578
.. _YAML : https://yaml.org/
0 commit comments