Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Serializer] Allow to pass a single value for the groups opt #10312

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
Sep 11, 2018
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
2 changes: 1 addition & 1 deletion components/serializer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ You are now able to serialize only attributes in the groups you want::
$normalizer = new ObjectNormalizer($classMetadataFactory);
$serializer = new Serializer(array($normalizer));

$data = $serializer->normalize($obj, null, array('groups' => array('group1')));
$data = $serializer->normalize($obj, null, array('groups' => 'group1'));
// $data = array('foo' => 'foo');

$obj2 = $serializer->denormalize(
Expand Down
9 changes: 8 additions & 1 deletion serializer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,16 @@ to your class and choose which groups to use when serializing::

$json = $serializer->serialize(
$someObject,
'json', array('groups' => array('group1'))
'json', array('groups' => 'group1')
);

.. tip::

The value of the ``groups`` key can be a single string, or an array of strings.

.. versionadded:: 4.2
The option to pass a single string to ``groups`` was introduced in Symfony 4.2.

In addition to the ``@Groups`` annotation, the Serializer component also
supports YAML or XML files. These files are automatically loaded when being
stored in one of the following locations:
Expand Down