我只收到来自FOSUser \ User +来自我的CaseWorker的ID的JSON结果,但仅此而已!结果如下所示:
{ "email": "tester@COM.de", "enabled": true, "id": 1 }
它应该是这样的:
{ "email": "tester@COM.de", "firstname": "Egon", "surname": "Olsen", "enabled": true, "id": 1 }
我做错了什么?
我的全局配置具有以下JMS和FOS条目:
#config.yml
...
fos_user:
db_driver: orm
firewall_name: default
user_class: COMP\CalcBundle\Entity\CaseWorker
jms_serializer:
metadata:
auto_detection: true
directories:
FOSUserBundle:
path: "@COMPCalcBundle/Resources/config/serializer/FOS"
namespace_prefix: FOS\UserBundle
parameters:
jms_serializer.serialized_name_annotation_strategy.class: JMS\Serializer\Naming\IdenticalPropertyNamingStrategy
隐藏FOS \ User属性的YML如下所示:
# src\COMP\CalcBundle\Resources\config\serializer\FOS\Entity.User.yml
FOS\UserBundle\Model\User:
exclusion_policy: ALL
properties:
email:
expose: true
enabled:
expose: true
我的caseworker实体看起来像这样:
# src\COMP\CalcBundle\Entity\CaseWorker.php
use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Model\User as BaseUser;
use JMS\Serializer\Annotation as JMS;
/**
* CaseWorker
*
* @ORM\Table(name="caseWorker", options={"collate"="utf8_general_ci"})
* @ORM\Entity
* @JMS\ExclusionPolicy("all")
*/
class CaseWorker extends BaseUser
{
/**
* @var integer
*
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue
* @JMS\Expose
*/
protected $id;
/**
* @var string
*
* @ORM\Column(type="string", length=80, nullable=true)
* @JMS\Expose
*/
private $firstname;
/**
* @var string
*
* @ORM\Column(type="string", length=80, nullable=true)
* @JMS\Expose
*/
private $surname;
/**
* @ORM\OneToMany(targetEntity="Event", mappedBy="caseworker")
**/
private $events;
...
答案 0 :(得分:0)
发现它!
问题是,序列化程序只序列化非空的字段! 所以在我的情况下,实体没有设置名字和姓氏!
我希望这有助于其他人!