8000 minor #10312 [Serializer] Allow to pass a single value for the groups… · symfony/symfony-docs@fd0ce36 · GitHub
[go: up one dir, main page]

Skip to content

Commit fd0ce36

Browse files
committed
minor #10312 [Serializer] Allow to pass a single value for the groups opt (dunglas, javiereguiluz)
This PR was merged into the master branch. Discussion ---------- [Serializer] Allow to pass a single value for the groups opt symfony/symfony#27503 Commits ------- ae558f4 Added the missing versionadded directive e4eae25 Replaced a "note" by a "tip" 5e0a91e [Serializer] Allow to pass a single value for the groups opt
2 parents 0907554 + ae558f4 commit fd0ce36

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

components/serializer.rst

L 10000 ines 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: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,16 @@ 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+
.. tip::
137+
138+
The value of the ``groups`` key can be a single string, or an array of strings.
139+
140+
.. versionadded:: 4.2
141+
The option to pass a single string to ``groups`` was introduced in Symfony 4.2.
142+
136143
In addition to the ``@Groups`` annotation, the Serializer component also
137144
supports YAML or XML files. These files are automatically loaded when being
138145
stored in one of the following locations:

0 commit comments

Comments
 (0)
0