0

シリアライゼーション グループは、1 つのエンティティをフェッチするときにうまく機能しますが、結果の配列をフェッチしようとすると、空の結果セットが得られます。

私はこれをそのようにします:

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