I am having a problem when serializing an instance Userwith one additional field $namethat extends the base user from FOSUserBundle:
<?php
namespace AppBundle\Entity\User;
use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Model\User as BaseUser;
class User extends BaseUser
{
private $name;
public function setName($name)
{
$this->name = $name;
return $this;
}
public function getName()
{
return $this->name;
}
}
To simplify, I only need to set the field $saltfrom the user object usingJMSSerializerBundle
FOS\UserBundle\Model\User:
exclusion_policy: all
properties:
salt:
expose: true
Here's the config for it:
jms_serializer:
metadata:
auto_detection: true
directories:
FOSUserBundle:
namespace_prefix: "FOS\\UserBundle"
path: "@AppBundle/Resources/config/serializer"
The problem is that the serializer also provides a field $namethat I don't need, since I only need to have $salt:
{
"salt": "abcdefg",
"name": "Admin"
}
It seems to me that I need to say that the serializer uses the configuration for mine AppBundle\Entity\Userinstead of the basic user object from FOSUserBundle, but I do not know how to implement it.