File tree Expand file tree Collapse file tree 1 file changed +19
-3
lines changed Expand file tree Collapse file tree 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::
162162 class MyObj
163163 {
164164 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+ }
166177 }
167178
168179The definition of serialization can be specified using annotations, XML
@@ -207,7 +218,12 @@ Then, create your groups definition:
207218 /**
208219 * @Groups({"group3"})
209220 */
210- public $bar;
221+ public function getBar() // is* methods are also supported
222+ {
223+ return $this->bar;
224+ }
225+
226+ // ...
211227 }
212228
213229 .. code-block :: yaml
@@ -246,7 +262,7 @@ You are now able to serialize only attributes in the groups you want::
246262
247263 $obj = new MyObj();
248264 $obj->foo = 'foo';
249- $obj->bar = 'bar';
265+ $obj->setBar( 'bar') ;
250266
251267 $normalizer = new ObjectNormalizer($classMetadataFactory);
252268 $serializer = new Serializer(array($normalizer));
You can’t perform that action at this time.
0 commit comments