From 39381686d5a52585fdc1c5d39a2e6b714e1e7435 Mon Sep 17 00:00:00 2001 From: JohJohan Date: Sun, 10 Oct 2021 20:28:50 +0200 Subject: [PATCH] 14123 [Serializer] Document denormalize groups value '*' --- components/serializer.rst | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) 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