Search code examples
symfonyserializationsonata-user-bundlejms-serializer

Cannot override serializer config in SonataUserBundle to hide properties


I am using SonataUserBundle and JMSSerializerBundle and I would like to hide the token and other properties of my serialized object.

The file I want to ovvride in SonataUserBundle is Resources/config/serializer/Model.User.xml .

Here is my configuration:

app/config.yml

jms_serializer: metadata: auto_detection: true directories: - { path: %kernel.root_dir%/Resources/SoantaUserBundle/serializer, namespace_prefix: 'Sonata\UserBundle' } - { path: %kernel.root_dir%/Resources/FOSUserBundle/serializer, namespace_prefix: 'FOS\UserBundle' }

and in app/Resources/SonataUserBundle/serializer I have tried 2 files.

Model.User.xml

<?xml version="1.0" encoding="UTF-8"?> <serializer> <class name="Sonata\UserBundle\Model\User" exclusion-policy="all" xml-root-name="user"> <property name="token" type="string" expose="false" since-version="1.0" groups="sonata_api_read,sonata_api_write,sonata_search" /> </class> </serializer>

Model.User.yml

Sonata\UserBundle\Model\User: exclusion_policy: ALL properties: token: expose: false

Both files dont seem to work.

I have managed to hide some properties from the FOSUserBundle, but seems I have troubles hiding the ones related to SonataUserBundle. I'm not sure if it's relevant but I would like to mention that I am using also am using HWIOauthBundle.

Any help will be greatly appreciated.


Solution

  • First, I don't think you need autodetection since you're specifying also the directories. Then you have a couple of typos in the sonata directory path:

    jms_serializer:
        metadata:
            directories:
                - { path: %kernel.root_dir%/Resources/SonataUserBundle/serializer, namespace_prefix: 'Sonata\UserBundle' }