Skip to content
Merged
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
35 changes: 35 additions & 0 deletions serializer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,41 @@ A service leveraging `APCu`_ (and APC for PHP < 5.5) is built-in.
),
));

Enabling a name converter
-------------------------

The use of a :ref:`name converter <component-serializer-converting-property-names-when-serializing-and-deserializing>` service can be defined in the configuration using the `name_converter` serializer parameter.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two ticks around name_converter as well

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think should start with some explanation as to what the current behavior is. Something like:

By default, each key in the final serialized data will match the each property
name exactly (e.g. ``firstName``). But by using a :ref:`name converter <component-serializer-converting-property-names-when-serializing-and-deserializing>`,
you can transform the property names (e.g. ``firstName`` to ``first_name``).


The built-in :ref:`CamelCase to snake_case name converter <using-camelized-method-names-for-underscored-attributes>` can be enabled by using the `serializer.name_converter.camel_case_to_snake_case` value:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This lines a bit too long - we need to shorten them after about 72 characters

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The serializer.name... needs two ticks, instead of just one


.. configuration-block::

.. code-block:: yaml

# app/config/config.yml
framework:
# ...
serializer:
name_converter: 'serializer.name_converter.camel_case_to_snake_case'

.. code-block:: xml

<!-- app/config/config.xml -->
<framework:config>
<!-- ... -->
<framework:serializer name-converter="serializer.name_converter.camel_case_to_snake_case" />
</framework:config>

.. code-block:: php

// app/config/config.php
$container->loadFromExtension('framework', array(
// ...
'serializer' => array(
'name_converter' => 'serializer.name_converter.camel_case_to_snake_case,
),
));

Going Further with the Serializer Component
-------------------------------------------

Expand Down