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

Skip to content
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