当我获取一个实体时,序列化组对我很有用 当我尝试获取结果数组时,我得到了空结果集。
我这样做:
* @\FOS\RestBundle\Controller\Annotations\View(serializerGroups={"client"})
但也尝试在视图对象上手动设置上下文,并且情况相同。 当我没有设置组或设置为"默认":
* @\FOS\RestBundle\Controller\Annotations\View(serializerGroups={"Default"})
我得到了正确的序列化结果集。
我的实体:
use JMS\Serializer\Annotation as JMS;
[...]
/**
* Document
*
* @ORM\Table(name="documents")
* @ORM\Entity(repositoryClass="AppBundle\Entity\DocumentRepository")
* @ORM\EntityListeners({"DocumentListener"})
* @JMS\ExclusionPolicy("all")
* @JMS\AccessorOrder("custom", custom = {"id", "folderId", "title"})
*/
class Document implements ResourceInterface
{
/**
* @var integer
*
* @ORM\Column(type="integer", name="id")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @JMS\Groups({"client"})
* @JMS\Expose()
*/
protected $id;
/**
* @var string
*
* @ORM\Column(type="text", name="description")
* @JMS\Groups({"client"})
* @JMS\Expose()
*/
protected $description;
[...]
和我的控制员:
// not working
/**
* @\FOS\RestBundle\Controller\Annotations\View(serializerGroups={"client"})
* @return Paginator
* @Get("/documents")
*/
public function documentsAction(ParamFetcher $params)
{
[...]
return ($this->getPaginator(
$params,
$documentBundle->get()
));
}
//works fine
/**
* Get document
*
* @QueryParam(name="id", requirements="\d+", nullable=false)
* @param ParamFetcher $params
* @\FOS\RestBundle\Controller\Annotations\View(serializerGroups={"client"})
*/
public function documentAction(ParamFetcher $params)
{
/** @var DocumentRepository $documentBundle */
$documentBundle = $this->getDoctrine()->getRepository('AppBundle:Document');
return $documentBundle->findByDocumentId($params->get('id'));
}
PS。
fosrestbundle 1.7.9
jmsserializer 0.16.0