Jms序列化器注释为yaml文件[英] Jms serializer annotations as yaml file

本文是小编为大家收集整理的关于Jms序列化器注释为yaml文件的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我一直在从FOSUserBundle继承的User类工作,所以我遇到了一个问题.我需要为我的User设置序列化,但是JMS序列化器将BaseUser的所有属性序列化. 我发现的解决方案是为BaseUser创建自己的注释并将其存储在YAML文件中,但是我不知道我应该怎么做.

推荐答案

JMSSerializerBundle默认使用您的AcmeBundle/Resources/config/serializer目录来获取在yml或xml文件中声明的所有元数据.您需要使用名称Entity.User.yml创建文件,以指向序列化器以使用您的AcmeBundle/Entity/User实体.

如果您需要定义第三方捆绑包(基本实体)的元数据,则可以定义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的名称的元数据文件.

本文地址:https://www.itbaoku.cn/post/2090828.html

问题描述

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 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.

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

In this case you need to locate your metadata file in %kernel.root_dir%/serializer/FOSUB directory with name like Model.User.yml.