File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -181,11 +181,15 @@ method on the normalizer definition::
181
181
As a final result, the deserializer uses the ``first_name `` attribute as if
182
182
it were ``firstName `` and uses the ``getFirstName `` and ``setFirstName `` methods.
183
183
184
- Using Callbacks to Serialize DateTime Objects
185
- ---------------------------------------------
184
+ Using Callbacks to Serialize Properties With Object Instances
185
+ -------------------------------------------------------------
186
186
187
- If you have DateTime type fields or need special formatting needs when deserializing
188
- a particular property from your object you can use the callbacks feature::
187
+ When serializing you can set a callback to format a specific object property.
188
+
189
+ use Symfony\C omponent\S erializer\E ncoder\J sonEncoder;
190
+ use Symfony\C omponent\S erializer\N ormalizer\G etSetMethodNormalizer;
191
+ use Symfony\C omponent\S erializer\S erializer;
192
+ use Acme\P erson;
189
193
190
194
$encoder = new JsonEncoder();
191
195
$normalizer = new GetSetMethodNormalizer();
@@ -200,7 +204,7 @@ a particular property from your object you can use the callbacks feature::
200
204
201
205
$serializer = new Serializer(array($normalizer), array($encoder));
202
206
203
- $person = new Acme\ Person();
207
+ $person = new Person();
204
208
$person->setName('cordoval');
205
209
$person->setAge(34);
206
210
$person->setCreatedAt(new \D ateTime('now'));
You can’t perform that action at this time.
0 commit comments