Skip to content

Commit 5d368de

Browse files
committed
[Serializer] Fixes in group support
1 parent 253cf72 commit 5d368de

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

components/serializer.rst

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,10 @@ Attributes Groups
146146
The support of serialization and deserialization groups was introduced
147147
in Symfony 2.7.
148148

149-
Sometimes, you want to serialize different set of attributes from your
149+
Sometimes, you want to serialize different sets of attributes from your
150150
entities. Groups are a handy way to achieve this need.
151151

152-
Assume you have the following object plain-old-PHP object::
152+
Assume you have the following plain-old-PHP object::
153153

154154
namespace Acme;
155155

@@ -217,8 +217,10 @@ Then, create your groups definition:
217217
218218
<?xml version="1.0" ?>
219219
<serializer xmlns="http://symfony.com/schema/dic/serializer-mapping"
220-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
221-
xsi:schemaLocation="http://symfony.com/schema/dic/serializer-mapping http://symfony.com/schema/dic/serializer-mapping/serializer-mapping-1.0.xsd">
220+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
221+
xsi:schemaLocation="http://symfony.com/schema/dic/serializer-mapping
222+
http://symfony.com/schema/dic/serializer-mapping/serializer-mapping-1.0.xsd"
223+
>
222224
<class name="Acme\MyObj">
223225
<attribute name="foo">
224226
<group>group1</group>
@@ -234,13 +236,13 @@ Then, create your groups definition:
234236
You are now able to serialize only attributes in the groups you want::
235237

236238
use Symfony\Component\Serializer\Serializer;
237-
use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer;
239+
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
238240

239241
$obj = new MyObj();
240242
$obj->foo = 'foo';
241243
$obj->bar = 'bar';
242244

243-
$normalizer = new PropertyNormalizer($classMetadataFactory);
245+
$normalizer = new ObjectNormalizer($classMetadataFactory);
244246
$serializer = new Serializer(array($normalizer));
245247

246248
$data = $serializer->normalize($obj, null, array('groups' => array('group1')));

0 commit comments

Comments
 (0)