schmittjoh / JMSSerializerBundle

Easily serialize, and deserialize data of any complexity (supports XML, JSON, YAML)
http://jmsyst.com/bundles/JMSSerializerBundle
MIT License
1.8k stars 312 forks source link

Yaml multiple config on same class but different method #504

Open Jerome1337 opened 8 years ago

Jerome1337 commented 8 years ago

I'm using JMSSerializerBundle with FOSRestBundle.

I use the yml reference to serialize datas on a given class but I have to use another config for a method inside this class but I can't create yml config file for a method.

// This is the class config
PowerDNSBundle\Entity\PowerDNSDomain:
exclusion_policy: ALL
properties:
    id:
        expose: true
        groups: [list, details]
    name:
        expose: true
        groups: [list, details]
    ownerId:
        expose: true
        groups: [list, details]
    createDate:
        expose: true
        groups: [list, details]

// This is th config I'm trying to use on my method
PowerDNSBundle\Entity\PowerDNSDomain:
    exclusion_policy: NONE
        properties:
        server:
            exclude: true

This is possible to do this with the YAML reference ?

Thank

tuxado commented 8 years ago

i am working on the same config perhabse you have probleme with exclusion_policy: NONE that overwrite exclusion_policy: ALL

I have a question for you relating the group configuration groups: [list, details] is this configuration work for you? because i use the same list, details and nothing work :(

stof commented 8 years ago

The issue is that you have a duplicate key PowerDNSBundle\Entity\PowerDNSDomain in your YAML file, which does not work (same than duplicate keys in PHP arrays don't work).

Jerome1337 commented 8 years ago

@tuxado Yes this is working well in my project, I just use add a group to my serialization context with something like this

$view->getSerializationContext()->setGroups('list');