Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4ff3a28

Browse filesBrowse files
mcfedrxabbuh
authored andcommitted
New normalizers
1 parent 1f4113f commit 4ff3a28
Copy full SHA for 4ff3a28

File tree

1 file changed

+27
-0
lines changed
Filter options

1 file changed

+27
-0
lines changed

‎components/serializer.rst

Copy file name to clipboardExpand all lines: components/serializer.rst
+27Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,32 @@ There are several types of normalizers available:
511511

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

514+
:class:`Symfony\\Component\\Serializer\\Normalizer\\JsonSerializableNormalizer`
515+
This normalizer works with classes that implement :phpclass:`JsonSerializable`.
516+
517+
It will call the :phpmethod:`JsonSerializable::jsonSerialize` method and
518+
then further normalize the result. This means that nested
519+
:phpclass:`JsonSerializable` classes will also be normalized.
520+
521+
This normalizer is particularly helpful when you want to gradually migrate
522+
from an existing codebase using simple :phpfunction:`json_encode` to the Symfony
523+
Serializer by allowing you to mix which normalizers are used for which classes.
524+
525+
Unlike with :phpfunction:`json_encode` circular references can be handled.
526+
527+
:class:`Symfony\\Component\\Serializer\\Normalizer\\DateTimeNormalizer`
528+
This normalizer converts :phpclass:`DateTimeInterface` objects (e.g.
529+
:phpclass:`DateTime` and :phpclass:`DateTimeImmutable`) into strings.
530+
By default it uses the RFC3339_ format.
531+
532+
:class:`Symfony\\Component\\Serializer\\Normalizer\\DataUriNormalizer`
533+
This normalizer converts :phpclass:`SplFileInfo` objects into a data URI
534+
string (``data:...``) such that files can be embedded into serialized data.
535+
536+
.. versionadded:: 3.1
537+
The ``JsonSerializableNormalizer``, ``DateTimeNormalizer`` and
538+
``DataUriNormalizer`` normalizers were added in Symfony 3.1
539+
514540
Handling Circular References
515541
----------------------------
516542

@@ -653,3 +679,4 @@ you indicate that you're expecting an array instead of a single object.
653679

654680
.. _`JMS serializer`: https://github.com/schmittjoh/serializer
655681
.. _Packagist: https://packagist.org/packages/symfony/serializer
682+
.. _RFC3339: https://tools.ietf.org/html/rfc3339#section-5.8

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.