I have trouble with the follow code
/** @Route("/{collection}/{id}", name="object", defaults={"_format" = "json"}) */
public function retrieveOne($collection, $id)
{
$collection = Inflector::classify($collection);
$object = $this->get('doctrine_mongodb.odm.document_manager')
->getRepository('NameBundle:' . $collection)
->find($id);
$response = new Response(json_encode($object));
return $response;
}
Document
use Doctrine\ODM\MongoDB\Mapping\Annotations as Mongo;
/**
* Entrada
*
* @Mongo\Document
*/
class Entrada
{
/**
* @Mongo\Id
*/
protected $id;
/**
* @Mongo\String
* @var int $type
*/
private $type;
/**
* @Mongo\String
* @var string $nombre
*/
private $nombre;
//.. setters and getters
}
and always i get {} in the response body.
NOTE: the query returns a object correctly
json_encodewill only encode public properties.So you could:
json_encode($object->toArray())