Skip to content

Finish #4308: Documentation for the new PropertyNormalizer #5028

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 5 commits into from
Mar 14, 2015
Merged
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
28 changes: 28 additions & 0 deletions components/serializer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ which Encoders and Normalizer are going to be available::

$serializer = new Serializer($normalizers, $encoders);

There are several normalizers available, e.g. the
:class:`Symfony\\Component\\Serializer\\Normalizer\\GetSetMethodNormalizer` or
the :class:`Symfony\\Component\\Serializer\\Normalizer\\PropertyNormalizer`.
To read more about them, refer to the `Normalizers`_ section of this page. All
the examples shown below use the ``GetSetMethodNormalizer``.

Serializing an Object
---------------------

Expand Down Expand Up @@ -238,6 +244,28 @@ When serializing, you can set a callback to format a specific object property::
$serializer->serialize($person, 'json');
// Output: {"name":"cordoval", "age": 34, "createdAt": "2014-03-22T09:43:12-0500"}

Normalizers
-----------

There are several types of normalizers available:

:class:`Symfony\\Component\\Serializer\\Normalizer\\GetSetMethodNormalizer`
This normalizer reads the content of the class by calling the "getters"
(public methods starting with "get"). It will denormalize data by calling
the constructor and the "setters" (public methods starting with "set").

Objects are serialized to a map of property names (method name stripped of
the "get" prefix and converted to lower case) to property values.

:class:`Symfony\\Component\\Serializer\\Normalizer\\PropertyNormalizer`
This normalizer directly reads and writes public properties as well as
**private and protected** properties. Objects are normalized to a map of
property names to property values.

.. versionadded:: 2.6 The
:class:`Symfony\\Component\\Serializer\\Normalizer\\PropertyNormalizer`
class was introduced in Symfony 2.6.

Handling Circular References
----------------------------

Expand Down