I am using Symfony 3, Doctrine 2, FOS Rest bundle and JMS Serializer. I am using the exclude all policy across my app and then selectively exposing fields.
On the User Entity, I want to be able to expose additional fields only for the current user.
For example on the normal api/user/{id} endpoint, I want to expose the normal data, but then for api/user/current I want to expose slightly more data.
Eg.
/**
* ...
* @Serializer\ExclusionPolicy("all")
*/
class Users implements UserInterface
{
/**
* @var string
* @Serializer\Expose
*
* @ORM\Column(name="name", type="string", length=255, nullable=true)
*/
private $name;
/**
* @var string
*
* @ORM\Column(name="secretfield", type="string", length=255, nullable=true)
*/
private $secretfield;
I have tried the @groups decorator, but that only works to further whittle down the fields and would require me changing loads and being careful to set the "default" group context everywhere.
I have seen the Dynamic Exclusion Strategy, mentioned in the docs, but I can't figure out if it is what I need or not and which variables are available to build an expression out of.
Any ideas what the best way to do this would be?