I'm building a small API using Symfony2 and some bundles. I'm using FOSMessageBundle
to send private messages in my app. I'm also using JMSSerializer
along FOSRestBundle
to output JSON objects.
I want to control what properties of my Message entity are serialized and sent as JSON. For this I'm using both annotations and YML config files and it works perfectly for all my entities and even my FOSUserBundle
User model. But for some reason it doesn't work for my Message entity. Here is my code :
My Mapping file
#/app/serializer/MyVendor/Entity.Message.yml
MyVendor\CoreBundle\Entity\Message:
exclusion_policy: None
properties :
sender :
expose : false
exclude : true
My Entity using annotations
<?php
namespace MyVendor\CoreBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use FOS\MessageBundle\Entity\Message as BaseMessage;
use FOS\MessageBundle\Model\ThreadInterface;
use FOS\MessageBundle\Model\ParticipantInterface;
use JMS\Serializer\Annotation\ExclusionPolicy;
use JMS\Serializer\Annotation\Expose;
/**
* @ExclusionPolicy("all")
*/
class Message extends BaseMessage
{
/**
* @var \FOS\MessageBundle\Model\ParticipantInterface
* @Exclude
*/
protected $sender;
Thanks
SOLVED I forgot to specify the metadata files path in config.yml
jms_serializer:
metadata:
auto_detection: true
directories:
FOSMessageBundle:
namespace_prefix: "FOS\\MessageBundle"
path: "%kernel.root_dir%/serializer/FOSMessageBundle"