Skip to content

Commit b7f6cce

Browse files
committed
Merge branch '4.4' into 5.1
* 4.4: [#14384] Minor grammar fix in versionadded directive Add missing options context
2 parents 5b8da6b + f97888b commit b7f6cce

File tree

1 file changed

+75
-13
lines changed

1 file changed

+75
-13
lines changed

components/serializer.rst

+75-13
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,24 @@ When serializing, you can set a callback to format a specific object property::
669669
Normalizers
670670
-----------
671671

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:
673690

674691
:class:`Symfony\\Component\\Serializer\\Normalizer\\ObjectNormalizer`
675692
This normalizer leverages the :doc:`PropertyAccess Component </components/property_access>`
@@ -739,6 +756,14 @@ There are several types of normalizers available:
739756
:class:`Symfony\\Component\\Serializer\\Normalizer\\ProblemNormalizer`
740757
Normalizes errors according to the API Problem spec `RFC 7807`_.
741758

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+
742767
.. _component-serializer-encoders:
743768

744769
Encoders
@@ -777,6 +802,11 @@ The Serializer component provides several built-in encoders:
777802
:class:`Symfony\\Component\\Serializer\\Encoder\\CsvEncoder`
778803
This encoder encodes and decodes data in `CSV`_.
779804

805+
.. note::
806+
807+
You can also create your own Encoder to use another structure. Read more at
808+
:doc:`/serializer/custom_encoders`.
809+
780810
All these encoders are enabled by default when using the Serializer component
781811
in a Symfony application.
782812

@@ -896,25 +926,56 @@ which defines the configuration options for the XmlEncoder an associative array:
896926

897927
These are the options available:
898928

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.
911953

912954
The ``YamlEncoder``
913955
~~~~~~~~~~~~~~~~~~~
914956

915957
This encoder requires the :doc:`Yaml Component </components/yaml>` and
916958
transforms from and to Yaml.
917959

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+
918979
Skipping ``null`` Values
919980
------------------------
920981

@@ -1469,6 +1530,7 @@ Learn more
14691530
.. _`PSR-1 standard`: https://www.php-fig.org/psr/psr-1/
14701531
.. _`JMS serializer`: https://github.com/schmittjoh/serializer
14711532
.. _RFC3339: https://tools.ietf.org/html/rfc3339#section-5.8
1533+
.. _`options with libxml`: https://www.php.net/manual/en/libxml.constants.php
14721534
.. _JSON: http://www.json.org/
14731535
.. _XML: https://www.w3.org/XML/
14741536
.. _YAML: https://yaml.org/

0 commit comments

Comments
 (0)