Skip to content

Commit fb9a7cd

Browse files
committed
minor #15909 14123 Document denormalize groups value '*' (JohJohan)
This PR was merged into the 5.4 branch. Discussion ---------- 14123 Document denormalize groups value '*' Fixes #14123. Commits ------- 3938168 14123 [Serializer] Document denormalize groups value '*'
2 parents 6fbe1d6 + 3938168 commit fb9a7cd

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

components/serializer.rst

Lines changed: 26 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,23 @@ 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+
// You can use `groups` with value `*` to get all groups:
408+
409+
$obj3 = $serializer->denormalize(
410+
['foo' => 'foo', 'anotherProperty' => 'anotherProperty', 'bar' => 'bar'],
411+
'MyObj',
412+
null,
413+
['groups' => ['*']]
414+
);
415+
// $obj2 = MyObj(foo: 'foo', anotherProperty: 'anotherProperty', bar: 'bar')
416+
392417
.. _ignoring-attributes-when-serializing:
393418

394419
Selecting Specific Attributes

0 commit comments

Comments
 (0)