问题
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