When attempting to serialize a model using traits, the JMSSerializer does not serialize the properties included in this trait. I use yaml to set up the serializer, but it seems like it is not working.
trait IdentityTrait
{
protected $id;
public function setId($id)
{
$this->id = $id;
return $this;
}
public function getId()
{
return $this->id;
}
}
class OurClass {
use IdentityTrait;
protected $test;
public function getTest() {
$this->test;
}
}
Used by JMSSerializerBundle, and the next yaml is in Resources/config/serializer/Model.Traits.IdentityTrait.yml
MyProject\Component\Core\Model\Traits\IdentityTrait:
exclusion_policy: NONE
properties:
id:
expose: true
And the configuration OurClassis inResources/config/serializer/Model.OurClass.yml
MyProject\Component\Core\Model\OurClass:
exclusion_policy: NONE
properties:
test:
expose: true
Some code has been ignored to focus on the problem.
user2359967
source
share