-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Updated the serializer/* articles to Symfony 4 #8687
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 all commits
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 |
---|---|---|
|
@@ -4,19 +4,23 @@ | |
How to Use the Serializer | ||
========================= | ||
|
||
Serializing and deserializing to and from objects and different formats (e.g. | ||
JSON or XML) is a very complex topic. Symfony comes with a | ||
:doc:`Serializer Component </components/serializer>`, which gives you some | ||
tools that you can leverage for your solution. | ||
Symfony provides a serializer to serialize/deserialize to and from objects and | ||
different formats (e.g. JSON or XML). Before using it, read the | ||
:doc:`Serializer component docs </components/serializer>` to get familiar with | ||
its philosophy and the normalizers and encoders terminology. | ||
|
||
In fact, before you start, get familiar with the serializer, normalizers | ||
and encoders by reading the :doc:`Serializer Component </components/serializer>`. | ||
.. _activating_the_serializer: | ||
|
||
Activating the Serializer | ||
Installing the Serializer | ||
------------------------- | ||
|
||
The ``serializer`` service is not available by default. To turn it on, activate | ||
it in your configuration: | ||
Before using the serializer, run this command to install it in your application: | ||
|
||
.. code-block:: terminal | ||
|
||
$ composer require serializer | ||
|
||
Then, enable the serializer in the framework config: | ||
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. This is needed? I see that indeed it is! Shouldn't we fix this with a recipe? It won't block this PR, but we should look into that. 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. Wait, no, I think this is wrong. I think it auto-enables when the serializer is present. |
||
|
||
.. configuration-block:: | ||
|
||
|
@@ -65,7 +69,7 @@ it in your configuration: | |
Using the Serializer Service | ||
---------------------------- | ||
|
||
Once enabled, the ``serializer`` service can be injected in any service where | ||
Once enabled, the serializer service can be injected in any service where | ||
you need it or it can be used in a controller:: | ||
|
||
// src/Controller/DefaultController.php | ||
|
@@ -85,7 +89,7 @@ you need it or it can be used in a controller:: | |
Adding Normalizers and Encoders | ||
------------------------------- | ||
|
||
Once enabled, the ``serializer`` service will be available in the container | ||
Once enabled, the serializer service will be available in the container | ||
and will be loaded with four :ref:`encoders <component-serializer-encoders>` | ||
(:class:`Symfony\\Component\\Serializer\\Encoder\\JsonEncoder`, | ||
:class:`Symfony\\Component\\Serializer\\Encoder\\XmlEncoder`, | ||
|
@@ -193,12 +197,12 @@ to your class and choose which groups to use when serializing:: | |
); | ||
|
||
In addition to the ``@Groups`` annotation, the Serializer component also | ||
supports Yaml or XML files. These files are automatically loaded when being | ||
supports YAML or XML files. These files are automatically loaded when being | ||
stored in one of the following locations: | ||
|
||
* The ``serialization.yml`` or ``serialization.xml`` file in | ||
* The ``serialization.yaml`` or ``serialization.xml`` file in | ||
the ``Resources/config/`` directory of a bundle; | ||
* All ``*.yml`` and ``*.xml`` files in the ``Resources/config/serialization/`` | ||
* All ``*.yaml`` and ``*.xml`` files in the ``Resources/config/serialization/`` | ||
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. Here it would be necessary to mention the mapping paths introduced by the user, the default translations path and the overridden ones, in the order they are loaded. |
||
directory of a bundle. | ||
|
||
.. _serializer-enabling-metadata-cache: | ||
|
@@ -302,9 +306,9 @@ take a look at how this bundle works. | |
|
||
.. toctree:: | ||
:maxdepth: 1 | ||
:glob: | ||
|
||
serializer/* | ||
serializer/encoders | ||
serializer/custom_encoders | ||
|
||
.. _`APCu`: https://github.com/krakjoe/apcu | ||
.. _`ApiPlatform`: https://github.com/api-platform/core | ||
|
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.
I don't like this. It's not something to fix now, but the user should be able to get all their basic info right here on this article. Probably more of the components docs need to move here.