Skip to content

Commit 239e4dc

Browse files
committed
Merge branch '5.4' into 6.0
* 5.4: 14123 [Serializer] Document denormalize groups value '*'
2 parents deeab79 + 6babc34 commit 239e4dc

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

components/serializer.rst

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,11 @@ Then, create your groups definition:
306306
*/
307307
public $foo;
308308
309+
/**
310+
* @Groups({"group4"})
311+
*/
312+
public $anotherProperty;
313+
309314
/**
310315
* @Groups("group3")
311316
*/
@@ -328,6 +333,9 @@ Then, create your groups definition:
328333
#[Groups(['group1', 'group2'])]
329334
public $foo;
330335
336+
#[Groups(['group4'])]
337+
public $anotherProperty;
338+
331339
#[Groups(['group3'])]
332340
public function getBar() // is* methods are also supported
333341
{
@@ -343,6 +351,8 @@ Then, create your groups definition:
343351
attributes:
344352
foo:
345353
groups: ['group1', 'group2']
354+
anotherProperty:
355+
groups: ['group4']
346356
bar:
347357
groups: ['group3']
348358
@@ -360,6 +370,10 @@ Then, create your groups definition:
360370
<group>group2</group>
361371
</attribute>
362372
373+
<attribute name="anotherProperty">
374+
<group>group4</group>
375+
</attribute>
376+
363377
<attribute name="bar">
364378
<group>group3</group>
365379
</attribute>
@@ -373,6 +387,7 @@ You are now able to serialize only attributes in the groups you want::
373387

374388
$obj = new MyObj();
375389
$obj->foo = 'foo';
390+
$obj->anotherProperty = 'anotherProperty';
376391
$obj->setBar('bar');
377392

378393
$normalizer = new ObjectNormalizer($classMetadataFactory);
@@ -382,13 +397,26 @@ You are now able to serialize only attributes in the groups you want::
382397
// $data = ['foo' => 'foo'];
383398

384399
$obj2 = $serializer->denormalize(
385-
['foo' => 'foo', 'bar' => 'bar'],
400+
['foo' => 'foo', 'anotherProperty' => 'anotherProperty', 'bar' => 'bar'],
386401
'MyObj',
387402
null,
388403
['groups' => ['group1', 'group3']]
389404
);
390405
// $obj2 = MyObj(foo: 'foo', bar: 'bar')
391406

407+
// To get all groups, use the special value `*` in `groups`
408+
$obj3 = $serializer->denormalize(
409+
['foo' => 'foo', 'anotherProperty' => 'anotherProperty', 'bar' => 'bar'],
410+
'MyObj',
411+
null,
412+
['groups' => ['*']]
413+
);
414+
// $obj2 = MyObj(foo: 'foo', anotherProperty: 'anotherProperty', bar: 'bar')
415+
416+
.. versionadded:: 5.2
417+
418+
The ``*`` special value for ``groups`` was introduced in Symfony 5.2.
419+
392420
.. _ignoring-attributes-when-serializing:
393421

394422
Selecting Specific Attributes

0 commit comments

Comments
 (0)