0
我正在用Symfony2和一些软件包构建一个小的API。我正在使用FOSMessageBundle
在我的应用中发送私人消息。 我还沿着FOSRestBundle
使用JMSSerializer
来输出JSON对象。FOSMessageBundle和JMSSerializer不能一起工作
我想控制我的消息实体的哪些属性被序列化并作为JSON发送。为此,我使用注释和YML配置文件,它适用于我所有的实体,甚至我的用户模型。但由于某种原因,它不适用于我的消息实体。这里是我的代码:
我的映射文件
#/app/serializer/MyVendor/Entity.Message.yml
MyVendor\CoreBundle\Entity\Message:
exclusion_policy: None
properties :
sender :
expose : false
exclude : true
我的实体使用注释
<?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;
感谢