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

Skip to content

Commit 5e0a91e

Browse files
committed
[Serializer] Allow to pass a single value for the groups opt
1 parent 8a88478 commit 5e0a91e

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

components/serializer.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ You are now able to serialize only attributes in the groups you want::
337337
$normalizer = new ObjectNormalizer($classMetadataFactory);
338338
$serializer = new Serializer(array($normalizer));
339339

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

343343
$obj2 = $serializer->denormalize(

serializer.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,13 @@ to your class and choose which groups to use when serializing::
130130

131131
$json = $serializer->serialize(
132132
$someObject,
133-
'json', array('groups' => array('group1'))
133+
'json', array('groups' => 'group1')
134134
);
135135

136+
.. note::
137+
138+
The value of the ``groups`` key can be a single string, or an array of strings.
139+
136140
In addition to the ``@Groups`` annotation, the Serializer component also
137141
supports YAML or XML files. These files are automatically loaded when being
138142
stored in one of the following locations:

0 commit comments

Comments
 (0)