JMS序列化程序批注作为yaml文件

JMS序列化程序批注作为yaml文件

本文介绍了JMS序列化程序批注作为yaml文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究从FOSUserBundleBaseUser继承的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目录来提取在ymlxml文件中声明的所有元数据.您需要创建名称为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文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 02:46