I want to expose only a few properties of my User class, using JMSSerializerBundle and FOSRestBundle. It seems like the serializer bundle is not reading my configuration file.
My User class is in src/AppBundle/Entity/User
and it extends the FOSUserBundle user class.
Here is my User class:
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Model\User as BaseUser;
use Symfony\Component\Validator\Constraints as Assert;
/**
* User
*
* @ORM\Table(name="backoffice_user")
* @ORM\Entity(repositoryClass="AppBundle\Entity\Repository\UserRepository")
*/
class User extends BaseUser
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var string
*
* @ORM\Column(name="lastname", type="string", length=70)
*/
private $lastname;
/**
* @var string
*
* @ORM\Column(name="firstname", type="string", length=70)
*/
private $firstname;
}
This is my app/config.yml file
jms_serializer:
metadata:
debug: true
auto_detection: true
And the yml mappgin file in src/AppBundle/Resources/config/serializer/Entity.User.yml
:
AppBundle\Entity\User:
exclusion_policy: ALL
exclude: true
properties:
email:
exclude: true
expose: true
The file is not read (or at least not taken into account), because my API returns me all fields of my entity.
Am I forgetting something ?