There is A LOT of similar quesions, some of them have validated answers, but here I am and none of them worked.
My use case is pretty simple:
My users
App\Client\common\Entities\Userbelong to a customerApp\Client\common\Entities\Customer.App\Client\common\Entities\Useralso inheritsFOS\UserBundle\Model\Userwhich contains the holy property "email"
I want to serialize all my customers AND their users (including their mail). Jms works pretty well except i can not access properties from the FOS\UserBundle\Model\User class.
following this answer here is what I have now.
jms_serializer.yml
jms_serializer: #blablablaa.... metadata: auto_detection: true directories: App: namespace_prefix: 'App\Client' path: '%kernel.project_dir%/serializer' FOSUB: namespace_prefix: 'FOS\UserBundle' path: '%kernel.project_dir%/serializer' serializer/App.Client.common.Entities.User.yml :
App\Client\common\Entities\User: exclusion_policy: ALL properties: surname: expose: true exclude: false groups: [export] serializer/Model.User.yml:
FOS\UserBundle\Model\User: exclusion_policy: ALL properties: email: expose: true exclude: false groups: [export] src/Command/DeploySyncUsersCommand.php:
protected function execute(InputInterface $input, OutputInterface $output) { $users = $this->customerRepository->findAll(); //this is an array of Customer $context = new SerializationContext(); $context->setGroups(['export']); $serializer = SerializerBuilder::create()->build(); $json = $serializer->serialize($users, 'json', $context); // do something with json } Everything works fine except the json does NOT contain email or any FOSUser\User data.
Also something interesting is that I can write anything (even invalid yml) in the App.Client.common.Entities.User.yml and Model.User.yml files, I'm able to clear the cache with no errors. I have errors when I write invalid yml in jms_serializer.yml