Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overriding groups of deeper branches of the graph #1121

Closed
inwaar opened this issue Sep 9, 2019 · 5 comments
Closed

Overriding groups of deeper branches of the graph #1121

inwaar opened this issue Sep 9, 2019 · 5 comments

Comments

@inwaar
Copy link

inwaar commented Sep 9, 2019

image

The documentation is not clear.
What do mean manager and friends array keys passed to setGroups in array?
Are those names of the properties on the object to be serialized?

Is this feature is working at all?
#1058

This seemed to remove part or all of it?

@goetas
Copy link
Collaborator

goetas commented Sep 10, 2019

Hi, the feature is part of jms/serializer v3.x as described. The PR is #1071

manager and friends are the names of properties of the User class available few lines before.

The main aim of the feature is to be able to set a generic group for the whole class, and a specific group for a particular property.

As example:

use JMS\Serializer\Annotation\Groups;

class User
{
    /** @Groups({"generic"}) */
    private $name;

    /** @Groups({"specific"}) */
    private $email;

    /** 
    * @var User 
    * @Groups({"generic"})
    * */
    private $manager;
}
$context = SerializationContext::create()->setGroups(array(
    'generic',
    'manager' => array(
        'specific', 
    ),
));

will produce something as

{
  "name": "John",
  "manager": {
     "email": "[email protected]"
  }
}

If you had only

$context = SerializationContext::create()->setGroups(array(
    'generic'
));

Result would have been:

{
  "name": "John",
  "manager": {
     "name": "Tom"
  }
}

@graanday
Copy link

Hi,
is it possible to set a specific group to each friend?
specific1 for 'John friend 1'
specific2 for 'John friend 2'

@scyzoryck
Copy link
Collaborator

@graanday do you mean different groups depending on the object value?

@graanday
Copy link

graanday commented Feb 28, 2024

@graanday do you mean different groups depending on the object value?

yes

I am referring to the example of the object graph in the documentation.
$john = new User( 'John', new User( 'John Manager', new User('The boss'), array( new User('John Manager friend 1'), ) ), array( new User( 'John friend 1', new User('John friend 1 manager') ), new User( 'John friend 2', new User('John friend 2 manager') ), ) );

@scyzoryck
Copy link
Collaborator

I guess you'd like to use it for the exclusion, right?
Then you can use ExpressionLanguageExclusionStrategy or implement your own Strategy ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants