I am setting up a REST service for my website with the FOSRestBundle and JMSSerializerBundle.
I made a custom method on a entity repository which returns a Paginator object. The method works great when I use it on the normal website, but when I want to use the method with the REST route, this error is thrown (XML or JSON output throws the same error) :
"Resources are not supported in serialized data."
I really don't know where to search since the error isn't very explicit to me.
Here's my AdsRestController.php :
<?php
namespace MyProject\MainBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use FOS\RestBundle\Controller\Annotations\View;
use FOS\RestBundle\Controller\Annotations\Get;
class AdsRestController extends Controller
{
/**
* @View
* @Get("/ads/list/all/{page}", requirements={"page" = "\id+"}, defaults={"page" = 1})
*/
public function getAdsListAllAction($page) {
$theAds = $this->getDoctrine()->getRepository('MyProjectMainBundle:Ads')->getAds($page);
return $theAds;
}
}
and my AdsRepository.php :
<?php
namespace MyProject\MainBundle\Entity;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Tools\Pagination\Paginator;
class AdsRepository extends EntityRepository
{
public function getAds($page=1, $maxPerPage=10)
{
$query = $this->createQueryBuilder('a')
->orderBy('a.date', $order)
;
$query->getQuery();
$query
->setFirstResult(($page-1) * $maxPerPage)
->setMaxResults($maxPerPage)
;
return new Paginator($query, true);
}
}
Any help would be highly appreciated !
Thanks.