Skip to content

Commit 608fead

Browse files
cordovalweaverryan
authored andcommitted
plug new revision
1 parent dce3cc2 commit 608fead

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

components/serializer.rst

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,15 @@ method on the normalizer definition::
181181
As a final result, the deserializer uses the ``first_name`` attribute as if
182182
it were ``firstName`` and uses the ``getFirstName`` and ``setFirstName`` methods.
183183

184-
Using Callbacks to Serialize DateTime Objects
185-
---------------------------------------------
184+
Using Callbacks to Serialize Properties With Object Instances
185+
-------------------------------------------------------------
186186

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\Component\Serializer\Encoder\JsonEncoder;
190+
use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer;
191+
use Symfony\Component\Serializer\Serializer;
192+
use Acme\Person;
189193

190194
$encoder = new JsonEncoder();
191195
$normalizer = new GetSetMethodNormalizer();
@@ -200,7 +204,7 @@ a particular property from your object you can use the callbacks feature::
200204

201205
$serializer = new Serializer(array($normalizer), array($encoder));
202206

203-
$person = new Acme\Person();
207+
$person = new Person();
204208
$person->setName('cordoval');
205209
$person->setAge(34);
206210
$person->setCreatedAt(new \DateTime('now'));

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy