@@ -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,22 @@ 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+
392416.. _ignoring-attributes-when-serializing :
393417
394418Selecting Specific Attributes
0 commit comments