Jms serializer annotations as yaml file

China☆狼群 提交于 2019-12-11 04:23:12

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/37670813/jms-serializer-annotations-as-yaml-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!