Reputation: 45
Im trying to develop an API (based on DoctrineMongoDBBundle and FOSRestBundle) that stores all the hole data in MongoDB, recovers it, and shows it using FOSRest.
When I try to show a list of objects stored in database this is what i'm getting:
"message": "Resources are not supported in serialized data. Path: Monolog\Handler\StreamHandler -> Symfony\Bridge\Monolog\Logger -> Doctrine\Bundle\MongoDBBundle\Logger\Logger -> Doctrine\Bundle\MongoDBBundle\Logger\AggregateLogger -> Doctrine\ODM\MongoDB\Configuration -> Doctrine\MongoDB\Connection -> Doctrine\ODM\MongoDB\LoggableCursor", "class": "JMS\Serializer\Exception\RuntimeException",
My config.yml for FOS is this:
fos_rest:
param_fetcher_listener: true
body_listener: true
format_listener: true
view:
view_response_listener: force
And that's my controller:
/**
* @Route("/services.{_format}", defaults={"_format" = "json"})
* @REST\View()
*/
public function getServicesAction($_format){
$services = $this->get('doctrine_mongodb')->getManager()
->getRepository('RadmasOpen010Bundle:Service')
->findAll();
return $services;
}
I tried to return a well formed Array, and no error were displayed, as well as if I join all the Service objects into an Array.
I tried to solve it installing Mongo PHP extension with PECL, changing some configs, but nothing has changed.
Anyone knows what cound be happening?
Upvotes: 1
Views: 3286
Reputation: 754
If you want to get a colection of RadmasOpen010Bundle:Service documents, you MUST call the method "toArray" after calling find method from repository or getQuery method from query builder
/**
* @Route("/services.{_format}", defaults={"_format" = "json"})
* @REST\View()
*/
public function getServicesAction($_format){
$services = $this->get('doctrine_mongodb')->getManager()
->getRepository('RadmasOpen010Bundle:Service')
->findAll()->toArray();
return $services;
}
also you can call array_values($services) for correct serialization of exclude strategy
Upvotes: 2