我已经像这样配置了 JMS 序列化器:
jms_serializer:
visitors:
xml_serialization:
format_output: '%kernel.debug%'
metadata:
auto_detection: true
directories:
App:
namespace_prefix: "App\\Entity"
path: "%kernel.root_dir%/serializer"
这是 src/serializer/SystemUser.yml 中元数据配置对于实体 SystemUser 的样子:
App\Entity\Api\Auth\SystemUser:
exclusion_policy: ALL
properties:
id:
expose: true
password:
expose: false
username:
expose: true
email:
expose: true
last_login:
expose: true
我专门使用了 .yml 扩展名,因为文档中提到必须在此处使用 .yml 扩展名:
https://jmsyst.com/bundles/JMSSerializerBundle/2.x/configuration#defining-metadata
我在 src/Entity/Api/Auth/SystemUser.php 中有如下实体:
<?php
namespace App\Entity\Api\Auth;
use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Model\User as BaseUser;
/**
* @ORM\Entity
* @ORM\Table(name="fos_user")
*/
class SystemUser extends BaseUser
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
public function __construct()
{
parent::__construct();
// your own logic
}
}
但是无论我在 SystemUser.yml 文件中排除什么属性,输出都不会改变。它显示所有属性。
我正在使用最新的 Symfony 4.3