diff --git a/components/serializer.rst b/components/serializer.rst
index acd7de09d6a..2d7a7ca8890 100644
--- a/components/serializer.rst
+++ b/components/serializer.rst
@@ -306,6 +306,11 @@ Then, create your groups definition:
*/
public $foo;
+ /**
+ * @Groups({"group4"})
+ */
+ public $anotherProperty;
+
/**
* @Groups("group3")
*/
@@ -328,6 +333,9 @@ Then, create your groups definition:
#[Groups(['group1', 'group2'])]
public $foo;
+ #[Groups(['group4'])]
+ public $anotherProperty;
+
#[Groups(['group3'])]
public function getBar() // is* methods are also supported
{
@@ -343,6 +351,8 @@ Then, create your groups definition:
attributes:
foo:
groups: ['group1', 'group2']
+ anotherProperty:
+ groups: ['group4']
bar:
groups: ['group3']
@@ -360,6 +370,10 @@ Then, create your groups definition:
group2
+
+ group4
+
+
group3
@@ -373,6 +387,7 @@ You are now able to serialize only attributes in the groups you want::
$obj = new MyObj();
$obj->foo = 'foo';
+ $obj->anotherProperty = 'anotherProperty';
$obj->setBar('bar');
$normalizer = new ObjectNormalizer($classMetadataFactory);
@@ -382,13 +397,23 @@ You are now able to serialize only attributes in the groups you want::
// $data = ['foo' => 'foo'];
$obj2 = $serializer->denormalize(
- ['foo' => 'foo', 'bar' => 'bar'],
+ ['foo' => 'foo', 'anotherProperty' => 'anotherProperty', 'bar' => 'bar'],
'MyObj',
null,
['groups' => ['group1', 'group3']]
);
// $obj2 = MyObj(foo: 'foo', bar: 'bar')
+ // You can use `groups` with value `*` to get all groups:
+
+ $obj3 = $serializer->denormalize(
+ ['foo' => 'foo', 'anotherProperty' => 'anotherProperty', 'bar' => 'bar'],
+ 'MyObj',
+ null,
+ ['groups' => ['*']]
+ );
+ // $obj2 = MyObj(foo: 'foo', anotherProperty: 'anotherProperty', bar: 'bar')
+
.. _ignoring-attributes-when-serializing:
Selecting Specific Attributes