Skip to content

[Serializer] Remove duplicate normalizers docs #14335

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions components/serializer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,8 @@ The Serializer component provides several built-in normalizers:
:class:`Symfony\\Component\\Serializer\\Normalizer\\PropertyNormalizer`
This normalizer directly reads and writes public properties as well as
**private and protected** properties (from both the class and all of its
parent classes). It supports calling the constructor during the denormalization process.
parent classes) by using `PHP reflection`_. It supports calling the constructor
during the denormalization process.

Objects are normalized to a map of property names to property values.

Expand Down Expand Up @@ -769,7 +770,7 @@ The Serializer component provides several built-in normalizers:
The ``DateTimeZoneNormalizer`` was introduced in Symfony 4.3.

:class:`Symfony\\Component\\Serializer\\Normalizer\\DataUriNormalizer`
This normalizer converts :phpclass:`SplFileInfo` objects into a data URI
This normalizer converts :phpclass:`SplFileInfo` objects into a `data URI`_
string (``data:...``) such that files can be embedded into serialized data.

:class:`Symfony\\Component\\Serializer\\Normalizer\\DateIntervalNormalizer`
Expand All @@ -781,9 +782,17 @@ The Serializer component provides several built-in normalizers:
:class:`Symfony\\Component\\Validator\\ConstraintViolationListInterface`
into a list of errors according to the `RFC 7807`_ standard.

.. versionadded:: 4.1

The ``ConstraintViolationListNormalizer`` was introduced in Symfony 4.1.

:class:`Symfony\\Component\\Serializer\\Normalizer\\ProblemNormalizer`
Normalizes errors according to the API Problem spec `RFC 7807`_.

.. versionadded:: 4.4

The ``ProblemNormalizer`` was introduced in Symfony 4.4.

:class:`Symfony\\Component\\Serializer\\Normalizer\\CustomNormalizer`
Normalizes a PHP object using an object that implements :class:`Symfony\\Component\\Serializer\\Normalizer\\NormalizableInterface`.

Expand Down Expand Up @@ -1601,3 +1610,5 @@ Learn more
.. _`Value Objects`: https://en.wikipedia.org/wiki/Value_object
.. _`API Platform`: https://api-platform.com
.. _`list of PHP timezones`: https://www.php.net/manual/en/timezones.php
.. _`PHP reflection`: https://php.net/manual/en/book.reflection.php
.. _`data URI`: https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs
39 changes: 10 additions & 29 deletions serializer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,36 +57,18 @@ Encoders supporting the following formats are enabled:

As well as the following normalizers:

* :class:`Symfony\\Component\\Serializer\\Normalizer\\ObjectNormalizer` to
handle typical data objects
* :class:`Symfony\\Component\\Serializer\\Normalizer\\DateTimeNormalizer` for
objects implementing the :phpclass:`DateTimeInterface` interface
* :class:`Symfony\\Component\\Serializer\\Normalizer\\DateTimeZoneNormalizer` for
:phpclass:`DateTimeZone` objects
* :class:`Symfony\\Component\\Serializer\\Normalizer\\ObjectNormalizer`
* :class:`Symfony\\Component\\Serializer\\Normalizer\\DateTimeNormalizer`
* :class:`Symfony\\Component\\Serializer\\Normalizer\\DateTimeZoneNormalizer`
* :class:`Symfony\\Component\\Serializer\\Normalizer\\DateIntervalNormalizer`
for :phpclass:`DateInterval` objects
* :class:`Symfony\\Component\\Serializer\\Normalizer\\DataUriNormalizer` to
transform :phpclass:`SplFileInfo` objects in `Data URIs`_
* :class:`Symfony\\Component\\Serializer\\Normalizer\\DataUriNormalizer`
* :class:`Symfony\\Component\\Serializer\\Normalizer\\JsonSerializableNormalizer`
to deal with objects implementing the :phpclass:`JsonSerializable` interface
* :class:`Symfony\\Component\\Serializer\\Normalizer\\ArrayDenormalizer` to
denormalize arrays of objects using a format like `MyObject[]` (note the `[]` suffix)
* :class:`Symfony\\Component\\Serializer\\Normalizer\\ConstraintViolationListNormalizer` for objects implementing the :class:`Symfony\\Component\\Validator\\ConstraintViolationListInterface` interface
* :class:`Symfony\\Component\\Serializer\\Normalizer\\ProblemNormalizer` for :class:`Symfony\\Component\\ErrorHandler\\Exception\\FlattenException` objects
* :class:`Symfony\\Component\\Serializer\\Normalizer\\ArrayDenormalizer`
* :class:`Symfony\\Component\\Serializer\\Normalizer\\ConstraintViolationListNormalizer`
* :class:`Symfony\\Component\\Serializer\\Normalizer\\ProblemNormalizer`

.. versionadded:: 4.1

The ``ConstraintViolationListNormalizer`` was introduced in Symfony 4.1.

.. versionadded:: 4.3

The ``DateTimeZoneNormalizer`` was introduced in Symfony 4.3.

.. versionadded:: 4.4

The ``ProblemNormalizer`` was introduced in Symfony 4.4.

Custom normalizers and/or encoders can also be loaded by tagging them as
Other :ref:`built-in normalizers <component-serializer-normalizers>` and
custom normalizers and/or encoders can also be loaded by tagging them as
:ref:`serializer.normalizer <reference-dic-tags-serializer-normalizer>` and
:ref:`serializer.encoder <reference-dic-tags-serializer-encoder>`. It's also
possible to set the priority of the tag in order to decide the matching order.
Expand All @@ -97,7 +79,7 @@ possible to set the priority of the tag in order to decide the matching order.
``DateTime`` or ``DateTimeImmutable`` classes to avoid excessive memory
usage and exposing internal details.

Here is an example on how to load the
Here is an example on how to load the built-in
:class:`Symfony\\Component\\Serializer\\Normalizer\\GetSetMethodNormalizer`, a
faster alternative to the `ObjectNormalizer` when data objects always use
getters (``getXxx()``), issers (``isXxx()``) or hassers (``hasXxx()``) to read
Expand Down Expand Up @@ -298,4 +280,3 @@ take a look at how this bundle works.
.. _`GraphQL`: https://graphql.org
.. _`JSON:API`: https://jsonapi.org
.. _`HAL`: http://stateless.co/hal_specification.html
.. _`Data URIs`: https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs
2 changes: 1 addition & 1 deletion serializer/custom_normalizer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ How to Create your Custom Normalizer

The :doc:`Serializer component </components/serializer>` uses
normalizers to transform any data into an array. The component provides several
:doc:`built-in normalizers </serializer/normalizers>` but you may need to create
:ref:`built-in normalizers <component-serializer-normalizers>` but you may need to create
your own normalizer to transform an unsupported data structure.

Creating a New Normalizer
Expand Down
29 changes: 2 additions & 27 deletions serializer/normalizers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,5 @@ Normalizers are enabled in the serializer passing them as its first argument::
Built-in Normalizers
--------------------

Symfony includes the following normalizers but you can also
:doc:`create your own normalizer </serializer/custom_normalizer>`:

* :class:`Symfony\\Component\\Serializer\\Normalizer\\ObjectNormalizer` to
normalize PHP object using the :doc:`PropertyAccess component </components/property_access>`;
* :class:`Symfony\\Component\\Serializer\\Normalizer\\DateTimeZoneNormalizer`
for :phpclass:`DateTimeZone` objects
* :class:`Symfony\\Component\\Serializer\\Normalizer\\DateTimeNormalizer` for
objects implementing the :phpclass:`DateTimeInterface` interface
* :class:`Symfony\\Component\\Serializer\\Normalizer\\DateIntervalNormalizer`
for :phpclass:`DateInterval` objects
* :class:`Symfony\\Component\\Serializer\\Normalizer\\DataUriNormalizer` to
transform :phpclass:`SplFileInfo` objects in `Data URIs`_
* :class:`Symfony\\Component\\Serializer\\Normalizer\\CustomNormalizer` to
normalize PHP object using an object that implements
:class:`Symfony\\Component\\Serializer\\Normalizer\\NormalizableInterface`;
* :class:`Symfony\\Component\\Serializer\\Normalizer\\GetSetMethodNormalizer` to
normalize PHP object using the getter and setter methods of the object;
* :class:`Symfony\\Component\\Serializer\\Normalizer\\PropertyNormalizer` to
normalize PHP object using `PHP reflection`_.
* :class:`Symfony\\Component\\Serializer\\Normalizer\\ConstraintViolationListNormalizer` for objects implementing the :class:`Symfony\\Component\\Validator\\ConstraintViolationListInterface` interface
* :class:`Symfony\\Component\\Serializer\\Normalizer\\ProblemNormalizer` for :class:`Symfony\\Component\\ErrorHandler\\Exception\\FlattenException` objects
* :class:`Symfony\\Component\\Serializer\\Normalizer\\JsonSerializableNormalizer`
to deal with objects implementing the :phpclass:`JsonSerializable` interface

.. _`Data URIs`: https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs
.. _`PHP reflection`: https://php.net/manual/en/book.reflection.php
Symfony includes several types of :ref:`built-in normalizers <component-serializer-normalizers>`
but you can also :doc:`create your own normalizer </serializer/custom_normalizer>`.