0

当我获取一个实体时,序列化组对我来说很好,但是当我尝试获取结果数组时,我得到了空的结果集。

我这样做:

 * @\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
4

0 回答 0