@@ -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
@@ -923,25 +953,51 @@ which defines the configuration options for the XmlEncoder an associative array:
923
953
924
954
These are the options available:
925
955
926
- ====================== ==================================================== ==========================
927
- Option Description Default
928
- ====================== ==================================================== ==========================
929
- ``xml_format_output `` If set to true, formats the generated XML with line
930
- breaks and indentation.
931
- ``xml_version `` Sets the XML version attribute ``1.1 ``
932
- ``xml_encoding `` Sets the XML encoding attribute ``utf-8 ``
933
- ``xml_standalone `` Adds standalone attribute in the generated XML ``true ``
934
- ``xml_root_node_name `` Sets the root node name (default: ``response ``).
935
- ``remove_empty_tags `` If set to true, removes all empty tags in the ``false ``
936
- generated XML
937
- ====================== ==================================================== ==========================
956
+ ============================== ================================================= ==========================
957
+ Option Description Default
958
+ ============================== ================================================= ==========================
959
+ ``xml_format_output `` If set to true, formats the generated XML with
960
+ line breaks and indentation.
961
+ ``xml_version `` Sets the XML version attribute ``1.1 ``
962
+ ``xml_encoding `` Sets the XML encoding attribute ``utf-8 ``
963
+ ``xml_standalone `` Adds standalone attribute in the generated XML ``true ``
964
+ ``xml_type_cast_attributes `` This provides the ability to forgot the attribute ``true ``
965
+ type casting
966
+ ``xml_root_node_name `` Sets the root node name (default: ``response ``).
967
+ ``as_collection `` Always returns results as a collection, even if
968
+ only one line is decoded
969
+ ``decoder_ignored_node_types `` Sets nodes to be ignored in the decode ``[\XML_PI_NODE, \XML_COMMENT_NODE] ``
970
+ ``encoder_ignored_node_types `` Sets nodes to be ignored in the encode ``[] ``
971
+ ``load_options `` XML loading `options with libxml `_ ``\LIBXML_NONET | \LIBXML_NOBLANKS ``
972
+ ``remove_empty_tags `` If set to true, removes all empty tags in the ``false ``
973
+ generated XML
974
+ ============================== ================================================= ==========================
938
975
939
976
The ``YamlEncoder ``
940
977
~~~~~~~~~~~~~~~~~~~
941
978
942
979
This encoder requires the :doc: `Yaml Component </components/yaml >` and
943
980
transforms from and to Yaml.
944
981
982
+ The ``YamlEncoder `` Context Options
983
+ ...................................
984
+
985
+ The ``encode() `` method, like other encoder, uses ``context `` to set
986
+ configuration options for the YamlEncoder an associative array::
987
+
988
+ $xmlEncoder->encode($array, 'xml', $context);
989
+
990
+ These are the options available:
991
+
992
+ =============== ================================================== ==========================
993
+ Option Description Default
994
+ =============== ================================================== ==========================
995
+ ``yaml_inline `` The level where you switch to inline YAML ``0 ``
996
+ ``yaml_indent `` The level of indentation (used internally) ``0 ``
997
+ ``yaml_flags `` A bit field of Yaml::DUMP_* / PARSE_* constants to ``0 ``
998
+ customize the encoding / decoding YAML string
999
+ =============== ================================================== ==========================
1000
+
945
1001
Skipping ``null `` Values
946
1002
------------------------
947
1003
@@ -1508,6 +1564,7 @@ Learn more
1508
1564
.. _`PSR-1 standard` : https://www.php-fig.org/psr/psr-1/
1509
1565
.. _`JMS serializer` : https://github.com/schmittjoh/serializer
1510
1566
.. _RFC3339 : https://tools.ietf.org/html/rfc3339#section-5.8
1567
+ .. _`options with libxml` : https://www.php.net/manual/en/libxml.constants.php
1511
1568
.. _JSON : http://www.json.org/
1512
1569
.. _XML : https://www.w3.org/XML/
1513
1570
.. _YAML : https://yaml.org/
0 commit comments