My configuration
jms_serializer: metadata: auto_detection: true directories: NameOfBundle: namespace_prefix: "" path: "@VendorNameOfBundle/Resources/config/serializer"
My Entity.Project.yml file called Entity.Project.yml contains
Vendor\NameOfBundle\Entity\Project: exclusion_policy: ALL properties: id: expose: true
I load a serializer, for example, from inside the controller
$serializer = SerializerBuilder::create() ->configureListeners(function(EventDispatcher $dispatcher) { $dispatcher->addSubscriber(new ProjectSubscriber($this->container)); }) ->addDefaultListeners() ->build();
This completely ignores my YML file and exposes all fields from Project. I cleared the cache.
But if I use this instead of the user subscriber, then the exceptions work
$serializer = $this->get("jms_serializer");
Even explicitly adding dir doesn't work either
$serializer = SerializerBuilder::create() ->configureListeners(function(EventDispatcher $dispatcher) { $dispatcher->addSubscriber(new ProjectSubscriber($this->container)); }) ->addDefaultListeners() ->addMetadataDir(realpath($this->get('kernel')->getRootDir()."/../") . '/src/Vendor/NameOfBundle/Resources/config/serializer') ->build();
The documents are not clear how this path should be set. The above method is not an error, but does not draw in YML files. Method errors are described below and indicate that the directory does not exist;
$serializer = SerializerBuilder::create() ->configureListeners(function(EventDispatcher $dispatcher) { $dispatcher->addSubscriber(new ProjectSubscriber($this->container)); }) ->addDefaultListeners() ->addMetadataDir('@VendorNameOfBundle/Resources/config/serializer') ->build();
How to get JMS Serializer to view my YML file to exclude fields as well as use a subscriber?