0
votes

I would like to exclude fields when exposing my API from my user class that extends FOSUser.

I've setup JMS Serializer on the global config file and created a FOSUB config to only expose the fields I need.

Global Config:

app/config/config.yml

jms_serializer:
    metadata:
        directories:
            FOSUB:
                namespace_prefix: "FOS\\UserBundle"
                path: "@AppBundle/Resources/config/serializer/fos"

FOS config file:

src/AppBundle/Resources/config/serializer/fos/Model.user.yml
FOS\UserBundle\Model\User:
    exclusion_policy: ALL
    properties:
        id:
            expose: true
        email:
            expose: true
        roles:
            expose: true

This config is working perfectly on my local machine however it doesn't work when deployed on prod. Both use same stack, my guess is that on prod somehow the serializer can't find FOS config file.

Any help would be much appreciated.

1

1 Answers

0
votes

The issue was somehow related to the naming of the config file.

While in local (macos) the file name Model.user.yml was working, in production (centos) it didn't work. So I had to rename the file to Model.User.yml then it worked fine on both.

I tried to find some documentation related to this issue but couldn't find any.

Take away: Make sure that the config file name represent exactly the entity you want to override.