Skip to content

Commit d6c0cb7

Browse files
committed
feature #5028 Finish #4308: Documentation for the new PropertyNormalizer (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
2 parents 50c8227 + 3b96301 commit d6c0cb7

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

components/serializer.rst

+28
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ which Encoders and Normalizer are going to be available::
5050

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

53+
There are several normalizers available, e.g. the
54+
:class:`Symfony\\Component\\Serializer\\Normalizer\\GetSetMethodNormalizer` or
55+
the :class:`Symfony\\Component\\Serializer\\Normalizer\\PropertyNormalizer`.
56+
To read more about them, refer to the `Normalizers`_ section of this page. All
57+
the examples shown below use the ``GetSetMethodNormalizer``.
58+
5359
Serializing an Object
5460
---------------------
5561

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

247+
Normalizers
248+
-----------
249+
250+
There are several types of normalizers available:
251+
252+
:class:`Symfony\\Component\\Serializer\\Normalizer\\GetSetMethodNormalizer`
253+
This normalizer reads the content of the class by calling the "getters"
254+
(public methods starting with "get"). It will denormalize data by calling
255+
the constructor and the "setters" (public methods starting with "set").
256+
257+
Objects are serialized to a map of property names (method name stripped of
258+
the "get" prefix and converted to lower case) to property values.
259+
260+
:class:`Symfony\\Component\\Serializer\\Normalizer\\PropertyNormalizer`
261+
This normalizer directly reads and writes public properties as well as
262+
**private and protected** properties. Objects are normalized to a map of
263+
property names to property values.
264+
265+
.. versionadded:: 2.6 The
266+
:class:`Symfony\\Component\\Serializer\\Normalizer\\PropertyNormalizer`
267+
class was introduced in Symfony 2.6.
268+
241269
Handling Circular References
242270
----------------------------
243271

0 commit comments

Comments
 (0)