@@ -669,7 +669,24 @@ When serializing, you can set a callback to format a specific object property::
669
669
Normalizers
670
670
-----------
671
671
672
- There are several types of normalizers available:
672
+ Normalizers turn **object ** into **array ** and vice versa. They implement
673
+ ::class: `Symfony\\ Component\\ Serializer\\ Normalizer\\ NormalizableInterface `
674
+ for normalize (object to array) and
675
+ :class: `Symfony\\ Component\\ Serializer\\ Normalizer\\ DenormalizableInterface ` for denormalize
676
+ (array to object).
677
+
678
+ You can add new normalizers to a Serializer instance by using its first constructor argument::
679
+
680
+ use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
681
+ use Symfony\Component\Serializer\Serializer;
682
+
683
+ $normalizers = [new ObjectNormalizer()];
684
+ $serializer = new Serializer($normalizers, []);
685
+
686
+ Built-in Normalizers
687
+ ~~~~~~~~~~~~~~~~~~~~
688
+
689
+ The Serializer component provides several built-in normalizers:
673
690
674
691
:class: `Symfony\\ Component\\ Serializer\\ Normalizer\\ ObjectNormalizer `
675
692
This normalizer leverages the :doc: `PropertyAccess Component </components/property_access >`
@@ -739,6 +756,14 @@ There are several types of normalizers available:
739
756
:class: `Symfony\\ Component\\ Serializer\\ Normalizer\\ ProblemNormalizer `
740
757
Normalizes errors according to the API Problem spec `RFC 7807 `_.
741
758
759
+ .. note ::
760
+
761
+ You can also create your own Normalizer to use another structure. Read more at
762
+ :doc: `/serializer/custom_normalizer `.
763
+
764
+ All these normalizers are enabled by default when using the Serializer component
765
+ in a Symfony application.
766
+
742
767
.. _component-serializer-encoders :
743
768
744
769
Encoders
@@ -777,6 +802,11 @@ The Serializer component provides several built-in encoders:
777
802
:class: `Symfony\\ Component\\ Serializer\\ Encoder\\ CsvEncoder `
778
803
This encoder encodes and decodes data in `CSV `_.
779
804
805
+ .. note ::
806
+
807
+ You can also create your own Encoder to use another structure. Read more at
808
+ :doc: `/serializer/custom_encoders `.
809
+
780
810
All these encoders are enabled by default when using the Serializer component
781
811
in a Symfony application.
782
812
@@ -896,25 +926,56 @@ which defines the configuration options for the XmlEncoder an associative array:
896
926
897
927
These are the options available:
898
928
899
- ====================== ==================================================== ==========================
900
- Option Description Default
901
- ====================== ==================================================== ==========================
902
- ``xml_format_output `` If set to true, formats the generated XML with line
903
- breaks and indentation.
904
- ``xml_version `` Sets the XML version attribute ``1.1 ``
905
- ``xml_encoding `` Sets the XML encoding attribute ``utf-8 ``
906
- ``xml_standalone `` Adds standalone attribute in the generated XML ``true ``
907
- ``xml_root_node_name `` Sets the root node name (default: ``response ``).
908
- ``remove_empty_tags `` If set to true, removes all empty tags in the ``false ``
909
- generated XML
910
- ====================== ==================================================== ==========================
929
+ ============================== ================================================= ==========================
930
+ Option Description Default
931
+ ============================== ================================================= ==========================
932
+ ``xml_format_output `` If set to true, formats the generated XML with
933
+ line breaks and indentation.
934
+ ``xml_version `` Sets the XML version attribute ``1.1 ``
935
+ ``xml_encoding `` Sets the XML encoding attribute ``utf-8 ``
936
+ ``xml_standalone `` Adds standalone attribute in the generated XML ``true ``
937
+ ``xml_type_cast_attributes `` This provides the ability to forgot the attribute ``true ``
938
+ type casting
939
+ ``xml_root_node_name `` Sets the root node name (default: ``response ``).
940
+ ``as_collection `` Always returns results as a collection, even if
941
+ only one line is decoded
942
+ ``decoder_ignored_node_types `` Sets nodes to be ignored in the decode ``[\XML_PI_NODE, \XML_COMMENT_NODE] ``
943
+ ``encoder_ignored_node_types `` Sets nodes to be ignored in the encode ``[] ``
944
+ ``load_options `` XML loading `options with libxml `_ ``\LIBXML_NONET | \LIBXML_NOBLANKS ``
945
+ ``remove_empty_tags `` If set to true, removes all empty tags in the ``false ``
946
+ generated XML
947
+ ============================== ================================================= ==========================
948
+
949
+ .. versionadded :: 4.2
950
+
951
+ The ``decoder_ignored_node_types `` and ``encoder_ignored_node_types ``
952
+ options were introduced in Symfony 4.2.
911
953
912
954
The ``YamlEncoder ``
913
955
~~~~~~~~~~~~~~~~~~~
914
956
915
957
This encoder requires the :doc: `Yaml Component </components/yaml >` and
916
958
transforms from and to Yaml.
917
959
960
+ The ``YamlEncoder `` Context Options
961
+ ...................................
962
+
963
+ The ``encode() `` method, like other encoder, uses ``context `` to set
964
+ configuration options for the YamlEncoder an associative array::
965
+
966
+ $xmlEncoder->encode($array, 'xml', $context);
967
+
968
+ These are the options available:
969
+
970
+ =============== ======================================================== ==========================
971
+ Option Description Default
972
+ =============== ======================================================== ==========================
973
+ ``yaml_inline `` The level where you switch to inline YAML ``0 ``
974
+ ``yaml_indent `` The level of indentation (used internally) ``0 ``
975
+ ``yaml_flags `` A bit field of ``Yaml::DUMP_* `` / ``PARSE_* `` constants ``0 ``
976
+ to customize the encoding / decoding YAML string
977
+ =============== ======================================================== ==========================
978
+
918
979
Skipping ``null `` Values
919
980
------------------------
920
981
@@ -1469,6 +1530,7 @@ Learn more
1469
1530
.. _`PSR-1 standard` : https://www.php-fig.org/psr/psr-1/
1470
1531
.. _`JMS serializer` : https://github.com/schmittjoh/serializer
1471
1532
.. _RFC3339 : https://tools.ietf.org/html/rfc3339#section-5.8
1533
+ .. _`options with libxml` : https://www.php.net/manual/en/libxml.constants.php
1472
1534
.. _JSON : http://www.json.org/
1473
1535
.. _XML : https://www.w3.org/XML/
1474
1536
.. _YAML : https://yaml.org/
0 commit comments