I´m tryng to implement the Symfony\Component\Serializer\Normalizer\NormalizableInterface using Symfony 2.0.9.
I added the implementation like this:
class MRoute implements NormalizableInterface{
...
public function normalize($object, $format = null)
{
$points = array();
foreach ($this->getPoints() as $point) {
$points[] = $point->normalize();
}
return array(
'id' => $this->getId(),
'name' => $this->getName(),
'points' => $points
);
}
/**
* @see
*/
function denormalize(NormalizerInterface $normalizer, $data, $format = null)
{
if (isset($data['name']))
{
$this->setName($data['name']);
}
if (isset($data['id']))
{
$this->setId($data['id']);
}
}
But when I try to acces the web service I get an error like this:
Fatal error: Declaration of MyGIS\GISBundle\Entity\MRoute::normalize() must be compatible with that of Symfony\Component\Serializer\Normalizer\NormalizableInterface::normalize() in C:\NetbeansProjects\mroute_rest_service\src\MyGIS\GISBundle\Entity\MRoute.php on line 16
I opened the Symfony\Component\Serializer\Normalizer\NormalizableInterface.php and the signatures match.
What am I doing wrong?
The interface in v2.0.9 is quite different from what you have pasted here:
https://github.com/symfony/symfony/blob/v2.0.9/src/Symfony/Component/Serializer/Normalizer/NormalizableInterface.php
It looks like you have implemented the 2.1 interface, which is totally different:
https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Serializer/Normalizer/NormalizableInterface.php
If you are in fact using 2.1 (the master branch) you need to add a
usestatement forNormalizerInterface.