8000 Updated the serializer/* articles to Symfony 4 by javiereguiluz · Pull Request #8687 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

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

Merged
merged 3 commits into from
Nov 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions serializer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Member

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.


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:
Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The 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::

Expand Down Expand Up @@ -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
Expand All @@ -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`,
Expand Down Expand Up @@ -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/``
Copy link
Member

Choose a reason for hiding this comment

The 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:
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions serializer/custom_encoders.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ to use another structure that's not supported.
Creating a new encoder
----------------------

Imagine you want to serialize and deserialize Yaml. For that you'll have to
Imagine you want to serialize and deserialize YAML. For that you'll have to
create your own encoder that uses the
:doc:`Yaml Component </components/yaml>`::

Expand Down Expand Up @@ -53,13 +53,13 @@ Registering it in your app

If you use the Symfony Framework. then you probably want to register this encoder
as a service in your app. If you're using the :ref:`default services.yml configuration <service-container-services-load-example>`,
that's done automatically!
that's done automatically!

.. tip::

If you're not using autoconfigure, make sure to register your class as a service
and tag it with ``serializer.encoder``.
If you're not using :ref:`autoconfigure <service_autoconfigure>`, make sure
to register your class as a service and tag it with ``serializer.encoder``.

Now you'll be able to serialize and deserialize Yaml!
Now you'll be able to serialize and deserialize YAML!

.. _tracker: https://github.com/symfony/symfony/issues
2 changes: 2 additions & 0 deletions service_container/3.3-di-changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,8 @@ In general, the new best practice is to use normal constructor dependency inject
(or "action" injection in controllers) instead of fetching public services via
``$this->get()`` (though that does still work).

.. _service_autoconfigure:

4) Auto-tagging with autoconfigure
----------------------------------

Expand Down
0