JMSSerializerBundle 和 FOSUser 不工作
JMSSerializerBundle and FOSUser not working
I only get a JSON result with everything from FOSUser\User + the ID from my CaseWorker exposed but nothing more! The result looks like the following:
{
"email": "tester@COM.de",
"enabled": true,
"id": 1
}
It should look like this:
{
"email": "tester@COM.de",
"firstname": "Egon",
"surname": "Olsen",
"enabled": true,
"id": 1
}
What do I do wrong?
我的全局配置包含以下 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
我的个案工作者实体如下所示:
# 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;
...
找到了!
问题是,序列化器只序列化不为空的字段!
所以在我的例子中,实体没有设置名字和姓氏!
我希望这对其他人有帮助!
I only get a JSON result with everything from FOSUser\User + the ID from my CaseWorker exposed but nothing more! The result looks like the following:
{ "email": "tester@COM.de", "enabled": true, "id": 1 }
It should look like this:
{ "email": "tester@COM.de", "firstname": "Egon", "surname": "Olsen", "enabled": true, "id": 1 }
What do I do wrong?
我的全局配置包含以下 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
我的个案工作者实体如下所示:
# 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;
...
找到了!
问题是,序列化器只序列化不为空的字段! 所以在我的例子中,实体没有设置名字和姓氏!
我希望这对其他人有帮助!