I am using FOSRest Bundle to build a small API in which I'd like to return a resource but only exposing some properties. I am using Symfony's default Serializer.
Here is my entity :
class myEntity
{
private foo;
* @Groups({"myGroup"})
private bar;
getFoo(){...}
getBar{...}
}
And my controller :
* @ParamConverter("myEntity ")
public function getAction(myEntity $myEntity)
{
$context = new Context();
$context->addGroups('myGroup');
$view = $this->view($myEntity, 200)->setTemplate("default/myEntity.html.twig")->setTemplateVar('myEntity');
$view->setContext($context);
return $this->handleView($view);
}
When I try to execute my controller, I get an empty object as a response : {}
If I remove the setContext() part, I get my whole entity including properties I don't want.
What am I doing wrong ? Thanks