symfony/symfony — pull request #3582 by tvlooy (2012-03-12 18:58:10+00:00)
Title: allow more control on GetSetMethodNormalizer

Here is an other attempt. You would use this as follows:

$serializer = new \Symfony\Component\Serializer\Serializer(
array(new \Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer()),
array('json' => new \Symfony\Component\Serializer\Encoder\JsonEncoder())
);

$callbacks = array('books' => function ($books) { return NULL; });

return new Response(
$serializer->serialize($paginator->getRows(), 'json', $callbacks),
200,
array('Content-Type' => 'application/json')
);

Besides of returning NULL, you could also do things like:

$callbacks = array(
'books' => function ($books) {
$ids = array();
foreach ($books as $book) {
$ids[] = $book->getId();
}
return $ids;
},
'author' => function ($author) {
return $author->getId();
},
'creationDate' => function ($creationDate) {
return $creationDate->format('d/m/Y');
},
);