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 at runtime does not work, or? #767

Closed
bblue opened this issue May 13, 2017 · 4 comments
Closed

Overriding groups at runtime does not work, or? #767

bblue opened this issue May 13, 2017 · 4 comments

Comments

@bblue
Copy link
Contributor

bblue commented May 13, 2017

I am trying to override the group for some properties at runtime, according to the documentation I can use the name of the property to assign new groups. The docs are not exactly clear on this point, but that is how I interpret it. I am however clearly doing something wrong, cause it doesn't work...

I have had a look at the GroupsExclusionStrategy and find it a bit strange. Does overriding groups even work now?

I looks to me to be missing some logic at the very top of shouldSkipUsingGroups. I would have added someting like (tested and works):

if(array_key_exists($property->name, $groups)) {
    $property->groups = array_unique(array_merge($property->groups, $groups[$property->name]));
}

Parts of the example in the documentation only work because there are no @group annotations assigned, so the prop becomes covered by the Default group by this logic.

My use case is when combing specific field exclusion with specific views AND embedded entities. i.e., I am providing a default view of shallow, and need to show a property that normally would only be visible if &view=deep was provided as a GET param. Were it not for the embedded fields I could simply manually set the view to deep, but that would cause my embedded classes to serialize with the deep view as well.

I have tested with 1.5, 1.6 and 1.7.

@bblue
Copy link
Contributor Author

bblue commented May 14, 2017

I see now that my quick-fix has some unwanted effects, but clearly it should be possible to also modify groups of the top level node. I haven't tried with child entities.

@goetas
Copy link
Collaborator

goetas commented May 14, 2017

hi, can you post some code of the expected result? I mean:

  • an entity example
  • a code to trigger serialization (with context info)
  • the expected result

thanks

@bblue
Copy link
Contributor Author

bblue commented May 18, 2017

Sorry for the delay. I was about to submit some non-working code examples, only to realize they were working...

I have not been able to find the root cause of my issue yet, but it is a split between myself misreading the docs, and some strange things going on with willdurand\hateoas bundle.

Essentially I was hoping for the group override functionality to also work on the object's own properties, and not just on deeper branches of the graph.

I realize the behavior I am looking for can be achieved with custom exclusion strategies, so I will probably go down that route.

@bblue bblue closed this as completed May 18, 2017
@bblue
Copy link
Contributor Author

bblue commented May 18, 2017

For reference for anyone else experiencing issues with willdurand hateoas, jms serializer and embedded objects:

It appears hateoas will serialize embedded objects by themselves, and then add the serialized data to the already serialized parent object. As such, there is no "deeper in the three"-logic to be applied by JMS. The serializer simply applies all its logic on that embedded object.

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

No branches or pull requests

2 participants