From 5e0a91e53b91a2d3930c7269479aa2863c0b5b9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Mon, 10 Sep 2018 17:24:01 +0200 Subject: [PATCH 1/3] [Serializer] Allow to pass a single value for the groups opt --- components/serializer.rst | 2 +- serializer.rst | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/components/serializer.rst b/components/serializer.rst index af35afdadc4..10540595da1 100644 --- a/components/serializer.rst +++ b/components/serializer.rst @@ -337,7 +337,7 @@ You are now able to serialize only attributes in the groups you want:: $normalizer = new ObjectNormalizer($classMetadataFactory); $serializer = new Serializer(array($normalizer)); - $data = $serializer->normalize($obj, null, array('groups' => array('group1'))); + $data = $serializer->normalize($obj, null, array('groups' => 'group1')); // $data = array('foo' => 'foo'); $obj2 = $serializer->denormalize( diff --git a/serializer.rst b/serializer.rst index f8d96782487..43f5cf04ebc 100644 --- a/serializer.rst +++ b/serializer.rst @@ -130,9 +130,13 @@ to your class and choose which groups to use when serializing:: $json = $serializer->serialize( $someObject, - 'json', array('groups' => array('group1')) + 'json', array('groups' => 'group1') ); +.. note:: + + The value of the ``groups`` key can be a single string, or an array of strings. + In addition to the ``@Groups`` annotation, the Serializer component also supports YAML or XML files. These files are automatically loaded when being stored in one of the following locations: From e4eae257d14bec7ace8a966e1fe5677da4a24f8a Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 11 Sep 2018 10:12:38 +0200 Subject: [PATCH 2/3] Replaced a "note" by a "tip" --- serializer.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/serializer.rst b/serializer.rst index 43f5cf04ebc..8c0610d3016 100644 --- a/serializer.rst +++ b/serializer.rst @@ -133,7 +133,7 @@ to your class and choose which groups to use when serializing:: 'json', array('groups' => 'group1') ); -.. note:: +.. tip:: The value of the ``groups`` key can be a single string, or an array of strings. From ae558f41df2ef5082a4e15d35b144832f7236346 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 11 Sep 2018 10:14:42 +0200 Subject: [PATCH 3/3] Added the missing versionadded directive --- serializer.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/serializer.rst b/serializer.rst index 8c0610d3016..25860b6ebf2 100644 --- a/serializer.rst +++ b/serializer.rst @@ -136,6 +136,9 @@ to your class and choose which groups to use when serializing:: .. tip:: The value of the ``groups`` key can be a single string, or an array of strings. + + .. versionadded:: 4.2 + The option to pass a single string to ``groups`` was introduced in Symfony 4.2. In addition to the ``@Groups`` annotation, the Serializer component also supports YAML or XML files. These files are automatically loaded when being