Hi,
I'm using Symfony 4 + FOSUserBundle for security reasons I have to hide some fields (email, password,..). For some reason, the metadata file locator is not called after I call the serialize method in a controller. Here is my configuration:
packages/jms_serializer.yaml
jms_serializer:
visitors:
xml:
format_output: '%kernel.debug%'
metadata:
auto_detection: true
directories:
FOSUB:
namespace_prefix: FOS\UserBundle
path: "%kernel.root_dir%/serializer"
src/serializer/FOSUB/Model.User.yml
FOS\UserBundle\Model\User:
exclusion_policy: ALL
properties:
firstName:
expose: true
composer
jms/metadata 1.6.0
jms/parser-lib 1.0.0
jms/serializer 1.13.0
jms/serializer-bundle 2.4.2
seeing your config, your file should be named src/serializer/Model.User.yml instead of src/serializer/FOSUB/Model.User.yml
I tried that before but that did not solve my issue. By the way, I change just the way you said but still, Exclusion policy is not happening for me.
I have updated the docs about this issue right few days ago... can you check that you did all the things in https://github.com/schmittjoh/JMSSerializerBundle/commit/6f45a525d1872fc533c0f40103ce0dda2ba70e57 ?
See the \\ as example... 99% of the cases this kind of issues were always mis-configurations.
I think I follow the documentation exactly, but I still have the same issue, that may be related to Symfony 4, because as I was searching for a solution I noticed many people using SF4 have the same problem. here is my directory structure:
- src
--- serializer
----- FOSUB
-------- Model.User.yml
jms_serializer:
visitors:
xml:
format_output: '%kernel.debug%'
metadata:
auto_detection: true
directories:
FOSUB:
namespace_prefix: "FOS\\UserBundle"
path: "%kernel.root_dir%/serializer/FOSUB"
I noticed that the issue was related to wrong way of calling the serializer:
instead of
$serializer = $this->get('jms_serializer');
I was doing :
$serializerBuilder = SerializerBuilder::create();
$serializerBuilder->setPropertyNamingStrategy(new \JMS\Serializer\Naming\IdenticalPropertyNamingStrategy());
$serializer = $serializerBuilder->build();
now it's fixed.
Most helpful comment
I noticed that the issue was related to wrong way of calling the serializer:
instead of
$serializer = $this->get('jms_serializer');I was doing :
now it's fixed.