Skip to content

Commit

Permalink
feature #5028 Finish #4308: Documentation for the new PropertyNormali…
Browse files Browse the repository at this point in the history
…zer (mnapoli, WouterJ)

This PR was merged into the 2.6 branch.

Discussion
----------

Finish #4308: Documentation for the new PropertyNormalizer

Finishes #4308

| Q | A
| --- | ---
| Doc fix? | no
| New docs? | yes (symfony/symfony#9708)
| Applies to | 2.6+
| Fixed tickets | #4272

Commits
-------

3b96301 Applied comments
629c8ac Added line returns…
6868a19 Updated the rendering of the list
4815c4a Introduction about normalizers
421aa41 ref #4272 Documentation for the new PropertyNormalizer introduced in symfony/symfony#9708
  • Loading branch information
weaverryan committed Mar 14, 2015
2 parents 50c8227 + 3b96301 commit d6c0cb7
Showing 1 changed file with 28 additions and 0 deletions.
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

0 comments on commit d6c0cb7

Please sign in to comment.