Skip to content

Commit cb50d14

Browse files
committed
feature #6926 [Serializer] Add information about name converter parameter (michaelperrin)
This PR was merged into the 2.8 branch. Discussion ---------- [Serializer] Add information about name converter parameter The `name_converter` option for the Serializer component configuration is only documented in the [configuration reference](http://symfony.com/doc/current/reference/configuration/framework.html#name-converter). It is not visible when reading the Serializer [How to use](http://symfony.com/doc/current/serializer.html) chapter, which makes difficult to find this option (hence an issue like this: https://github.com/symfony/symfony-standard/issues/902). Should I mention that the option was added in Symfony 2.8 (something that is not mentioned in the Configuration reference)? Commits ------- 299ac85 [Serializer] Add information about name converter parameter
2 parents fa8d09f + 299ac85 commit cb50d14

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

serializer.rst

+35
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,41 @@ A service leveraging `APCu`_ (and APC for PHP < 5.5) is built-in.
226226
),
227227
));
228228
229+
Enabling a name converter
230+
-------------------------
231+
232+
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.
233+
234+
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:
235+
236+
.. configuration-block::
237+
238+
.. code-block:: yaml
239+
240+
# app/config/config.yml
241+
framework:
242+
# ...
243+
serializer:
244+
name_converter: 'serializer.name_converter.camel_case_to_snake_case'
245+
246+
.. code-block:: xml
247+
248+
<!-- app/config/config.xml -->
249+
<framework:config>
250+
<!-- ... -->
251+
<framework:serializer name-converter="serializer.name_converter.camel_case_to_snake_case" />
252+
</framework:config>
253+
254+
.. code-block:: php
255+
256+
// app/config/config.php
257+
$container->loadFromExtension('framework', array(
258+
// ...
259+
'serializer' => array(
260+
'name_converter' => 'serializer.name_converter.camel_case_to_snake_case,
261+
),
262+
));
263+
229264
Going Further with the Serializer
230265
---------------------------------
231266

0 commit comments

Comments
 (0)