Serialization groups work for me fine when i fetch one entity but when i try fetch array of results i got empty result set.
I do this like that:
* @\FOS\RestBundle\Controller\Annotations\View(serializerGroups={"client"})
but also tried manually set context on view object, and same situation. When i don't set group or set to "Default":
* @\FOS\RestBundle\Controller\Annotations\View(serializerGroups={"Default"})
i got proper serialized result set.
My entity:
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;
[...]
and my controller:
// 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