@@ -146,10 +146,10 @@ Attributes Groups
146
146
The support of serialization and deserialization groups was introduced
147
147
in Symfony 2.7.
148
148
149
- Sometimes, you want to serialize different set of attributes from your
149
+ Sometimes, you want to serialize different sets of attributes from your
150
150
entities. Groups are a handy way to achieve this need.
151
151
152
- Assume you have the following object plain-old-PHP object::
152
+ Assume you have the following plain-old-PHP object::
153
153
154
154
namespace Acme;
155
155
@@ -217,8 +217,10 @@ Then, create your groups definition:
217
217
218
218
<?xml version =" 1.0" ?>
219
219
<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
+ >
222
224
<class name =" Acme\MyObj" >
223
225
<attribute name =" foo" >
224
226
<group >group1</group >
@@ -234,13 +236,13 @@ Then, create your groups definition:
234
236
You are now able to serialize only attributes in the groups you want::
235
237
236
238
use Symfony\Component\Serializer\Serializer;
237
- use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer ;
239
+ use Symfony\Component\Serializer\Normalizer\ObjectNormalizer ;
238
240
239
241
$obj = new MyObj();
240
242
$obj->foo = 'foo';
241
243
$obj->bar = 'bar';
242
244
243
- $normalizer = new PropertyNormalizer ($classMetadataFactory);
245
+ $normalizer = new ObjectNormalizer ($classMetadataFactory);
244
246
$serializer = new Serializer(array($normalizer));
245
247
246
248
$data = $serializer->normalize($obj, null, array('groups' => array('group1')));
0 commit comments