I am using this in config.yml:
# JMSSerializer Configuration
jms_serializer:
#parameters:
#jms_serializer.camel_case_naming_strategy.class: JMS\Serializer\Naming\IdenticalPropertyNamingStrategy
metadata:
cache: file
debug: "%kernel.debug%"
file_cache:
dir: "%kernel.cache_dir%/serializer"
auto_detection: true
directories:
AppBundle:
namespace_prefix: "AppBundle"
path: "%kernel.root_dir%/config/serializer/AppBundle"
And this in Entity.Category.yml:
AppBundle\Entity\Category:
exclusion_policy: ALL
But when i try to send request, i receive this error:
Expected metadata for class AppBundle\\Entity\\Category to be defined in /var/www/test/app/config/serializer/AppBundle/Entity.Category.yml.
How can I solve this issue?
你忘记了第 2 行的TAB
。
It looks like you are getting an incorrect path to your project files with %kernel.root_dir%
. Make sure that /var/www/test/app
is the correct path to your project. Check your PHP __DIR__
constant and try replacing `%kernel.root_dir% with what that says as well as what you think the path should be.
Also, instead of defining your exclusion policy in a config file you should just be able to annotate your entity like so and expose things as needed:
use JMS\Serializer\Annotation as JMS;
/**
* Class ExampleEntity
*
* @JMS\ExclusionPolicy("all")
* @ORM\Entity()
*/
class ExampleEntity
{
}
JMS annotations are foundhere .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.