Symfony的3.1.7 + FOSRestBundle最新版本组注释不会工作
<?php
namespace PM\ApiBundle\Controller;
...
use FOS\RestBundle\Controller\Annotations as Rest;
use FOS\RestBundle\View\View;
class ArticlesController extends FOSRestController
{
/**
* @ApiDoc(
* section="articles",
* resource=true,
* description="Get articles published"
*)
* @Rest\View(serializerGroups={"article"})
* @Rest\Get("/articles")
*/
public function getArticlesAction(Request $request)
{
$articles = $this->getDoctrine()
->getManager()
->getRepository('PMPlatformBundle:Article')
->findAllDateDesc();
/* @var $articles Article[] */
return $articles;
}
然后在我的文章实体添加此注释@Groups({“文章”})与使用权声明。
白衣默认的序列获得:
[
[],
[]
]
白衣JMS串行器(束)我得到:
{
"0": {},
"1": {}
}
(我在DB的两篇文章) 看起来像 “文章” 组不被认可。当我使用缺省的序列化程序而没有这个注释时,我得到一个循环错误。
怎么了?
[编辑]相同的行为与
/**
* @ApiDoc(
* section="articles",
* resource=true,
* description="Get articles published"
*)
* @Rest\View()
* @Rest\Get("/articles")
*/
public function getArticlesAction(Request $request)
{
$context = new Context();
$context->addGroup('article');
$articles = $this->getDoctrine()
->getManager()
->getRepository('PMPlatformBundle:Article')
->findAllDateDesc();
/* @var $articles Article[] */
$view = $this->view($articles, 200);
$view->setContext($context);
return $view;
}
的响应仍然是空的。
请问您可以告诉我们您的findAllDateDesc()方法返回的内容(var_dump或print_r)/您可以粘贴您的实体或序列器配置的代码吗? –
我的方法findAllDateDesc()工作正常(和debbuging,上帝!不使用var_dump或print_r,personnaly我使用xdebug ..),我的实体在这里不是问题,序列化程序也是。我回答了我的问题,我使用JMS序列化程序修复了这个问题。任何方式感谢您的帮助! –