-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[Serializer] Add new default normalizers #7493
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,19 +82,30 @@ you need it or it can be used in a controller like the following:: | |
Adding Normalizers and Encoders | ||
------------------------------- | ||
|
||
Once enabled, the ``serializer`` service will be available in the container | ||
and will be loaded with two :ref:`encoders <component-serializer-encoders>` | ||
(:class:`Symfony\\Component\\Serializer\\Encoder\\JsonEncoder` and | ||
:class:`Symfony\\Component\\Serializer\\Encoder\\XmlEncoder`) and the | ||
:ref:`ObjectNormalizer normalizer <component-serializer-normalizers>`. | ||
Once enabled, the ``serializer`` service will be available in the container. It comes with a set of useful :ref:`encoders <component-serializer-encoders>` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remember to keep lines shorter than 80 characters. |
||
and `normalizers <component-serializer-normalizers>`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. doesn't it miss |
||
|
||
You can load normalizers and/or encoders by tagging them as | ||
Encoders supporting the following formats are enabled: | ||
|
||
* JSON: :class:`Symfony\\Component\\Serializer\\Encoder\\JsonEncoder` | ||
* XML: :class:`Symfony\\Component\\Serializer\\Encoder\\XmlEncoder` | ||
|
||
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 :class:`DateTimeInterface` interface | ||
* :class:`Symfony\\Component\\Serializer\\Normalizer\\DataUriNormalizer` to transform :class:`SplFileInfo` objects in `Data URIs`_ | ||
* :class:`Symfony\\Component\\Serializer\\Normalizer\\JsonSerializableNormalizer` to deal with object implementing the :class:`JsonSerializable` interface | ||
* :class:`Symfony\\Component\\Serializer\\Normalizer\\ArrayDenormalizer` to denormalize arrays of objects using a format like `MyObject[]` (note the `[]` suffix) | ||
|
||
You can also load custom normalizers and/or encoders by tagging them as | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Custom normalizers/encoders can also be loaded by tagging..." |
||
: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. | ||
|
||
Here is an example on how to load the | ||
:class:`Symfony\\Component\\Serializer\\Normalizer\\GetSetMethodNormalizer`: | ||
:class:`Symfony\\Component\\Serializer\\Normalizer\\GetSetMethodNormalizer`, a faster alternative to the `ObjectNormalizer` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be on two lines |
||
if your data objects always use getters and setters: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "When data objects always ..." |
||
|
||
.. configuration-block:: | ||
|
||
|
@@ -283,3 +294,4 @@ take a look at how this bundle works. | |
.. _`ApiPlatform`: https://github.com/api-platform/core | ||
.. _`JSON-LD`: http://json-ld.org | ||
.. _`Hydra Core Vocabulary`: http://hydra-cg.com | ||
.. _`Data URIs`: https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be on two lines