File tree 1 file changed +19
-3
lines changed
1 file changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -162,7 +162,18 @@ Assume you have the following plain-old-PHP object::
162
162
class MyObj
163
163
{
164
164
public $foo;
165
- public $bar;
165
+
166
+ private $bar;
167
+
168
+ public function getBar()
169
+ {
170
+ return $this->bar;
171
+ }
172
+
173
+ public function setBar($bar)
174
+ {
175
+ return $this->bar = $bar;
176
+ }
166
177
}
167
178
168
179
The definition of serialization can be specified using annotations, XML
@@ -207,7 +218,12 @@ Then, create your groups definition:
207
218
/**
208
219
* @Groups({"group3"})
209
220
*/
210
- public $bar;
221
+ public function getBar() // is* methods are also supported
222
+ {
223
+ return $this->bar;
224
+ }
225
+
226
+ // ...
211
227
}
212
228
213
229
.. code-block :: yaml
@@ -246,7 +262,7 @@ You are now able to serialize only attributes in the groups you want::
246
262
247
263
$obj = new MyObj();
248
264
$obj->foo = 'foo';
249
- $obj->bar = 'bar';
265
+ $obj->setBar( 'bar') ;
250
266
251
267
$normalizer = new ObjectNormalizer($classMetadataFactory);
252
268
$serializer = new Serializer(array($normalizer));
You can’t perform that action at this time.
0 commit comments