Skip to content

Commit 1a8d0dc

Browse files
tvlooyweaverryan
authored andcommitted
Improve serialization example
Improve serialization example | Q | A | ------------- | --- | Doc fix? | yes | New docs? | yes | Applies to | all | Fixed tickets | symfony#2225
1 parent 866af09 commit 1a8d0dc

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

components/serializer.rst

+5-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,11 @@ use the Serializer service created before::
9090
$person->setName('foo');
9191
$person->setAge(99);
9292

93-
$serializer->serialize($person, 'json'); // Output: {"name":"foo","age":99}
93+
$jsonContent = $serializer->serialize($person, 'json');
94+
95+
// $jsonContent contains {"name":"foo","age":99}
96+
97+
echo $jsonContent; // or return it in a Response
9498

9599
The first parameter of the :method:`Symfony\\Component\\Serializer\\Serializer::serialize`
96100
is the object to be serialized and the second is used to choose the proper encoder,

0 commit comments

Comments
 (0)