@@ -306,6 +306,11 @@ Then, create your groups definition:
306
306
*/
307
307
public $foo;
308
308
309
+ /**
310
+ * @Groups({"group4"})
311
+ */
312
+ public $anotherProperty;
313
+
309
314
/**
310
315
* @Groups("group3")
311
316
*/
@@ -328,6 +333,9 @@ Then, create your groups definition:
328
333
#[Groups(['group1', 'group2'])]
329
334
public $foo;
330
335
336
+ #[Groups(['group4'])]
337
+ public $anotherProperty;
338
+
331
339
#[Groups(['group3'])]
332
340
public function getBar() // is* methods are also supported
333
341
{
@@ -343,6 +351,8 @@ Then, create your groups definition:
343
351
attributes :
344
352
foo :
345
353
groups : ['group1', 'group2']
354
+ anotherProperty :
355
+ groups : ['group4']
346
356
bar :
347
357
groups : ['group3']
348
358
@@ -360,6 +370,10 @@ Then, create your groups definition:
360
370
<group >group2</group >
361
371
</attribute >
362
372
373
+ <attribute name =" anotherProperty" >
374
+ <group >group4</group >
375
+ </attribute >
376
+
363
377
<attribute name =" bar" >
364
378
<group >group3</group >
365
379
</attribute >
@@ -373,6 +387,7 @@ You are now able to serialize only attributes in the groups you want::
373
387
374
388
$obj = new MyObj();
375
389
$obj->foo = 'foo';
390
+ $obj->anotherProperty = 'anotherProperty';
376
391
$obj->setBar('bar');
377
392
378
393
$normalizer = new ObjectNormalizer($classMetadataFactory);
@@ -382,13 +397,23 @@ You are now able to serialize only attributes in the groups you want::
382
397
// $data = ['foo' => 'foo'];
383
398
384
399
$obj2 = $serializer->denormalize(
385
- ['foo' => 'foo', 'bar' => 'bar'],
400
+ ['foo' => 'foo', 'anotherProperty' => 'anotherProperty', ' bar' => 'bar'],
386
401
'MyObj',
387
402
null,
388
403
['groups' => ['group1', 'group3']]
389
404
);
390
405
// $obj2 = MyObj(foo: 'foo', bar: 'bar')
391
406
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
+
392
417
.. _ignoring-attributes-when-serializing :
393
418
394
419
Selecting Specific Attributes
0 commit comments