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..25860b6ebf2 100644 --- a/serializer.rst +++ b/serializer.rst @@ -130,9 +130,16 @@ to your class and choose which groups to use when serializing:: $json = $serializer->serialize( $someObject, - 'json', array('groups' => array('group1')) + 'json', array('groups' => 'group1') ); +.. 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 stored in one of the following locations: