问题描述
我一直在研究从FOSUserBundle
的BaseUser
继承的User
类,所以遇到了一个问题.我需要为User
设置序列化,但是JMS序列化器会序列化BaseUser
的所有属性.我发现的解决方案是为BaseUser
创建自己的注释并将其存储在yaml文件中,但我不知道该怎么做.
I've been working on User
class inherited from BaseUser
of FOSUserBundle
, so I've faced a problem. I need to set up serialization for my User
but JMS serializer serializes all properties of BaseUser
.Solution that I found was to create my own annotation for BaseUser
and store it in yaml file, but I don't know how exactly should I do this.
推荐答案
JMSSerializerBundle默认情况下使用您的AcmeBundle/Resources/config/serializer
目录来提取在yml
或xml
文件中声明的所有元数据.您需要创建名称为Entity.User.yml
的文件以指向序列化程序以使用您的AcmeBundle/Entity/User
实体.
JMSSerializerBundle by default use your AcmeBundle/Resources/config/serializer
directory to fetch all metadata that are declared in yml
or xml
files. You need to create file with name Entity.User.yml
to point serializer to use your AcmeBundle/Entity/User
entity.
如果您需要为第三方捆绑软件(基本实体)定义元数据,则可以在config.yml
中定义用于获取元数据的自定义路径:
If you need to define metadata for third party bundles (base entities) you can define custom path for fetching metadata in config.yml
:
jms_serializer:
metadata:
directories:
FOSUB:
namespace_prefix: FOS\UserBundle
path: %kernel.root_dir%/serializer/FOSUB
在这种情况下,您需要在%kernel.root_dir%/serializer/FOSUB
目录中找到名称类似于Model.User.yml
的元数据文件.
In this case you need to locate your metadata file in %kernel.root_dir%/serializer/FOSUB
directory with name like Model.User.yml
.
这篇关于JMS序列化程序批注作为yaml文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!