-
Notifications
You must be signed in to change notification settings - Fork 118
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
MaxDepth exclusion strategy #136
Comments
Would you mind creating a test case or some code so that I better understand what does not work ? The RelationPropertyMetadata ( https://github.com/willdurand/Hateoas/blob/master/src/Hateoas/Serializer/Metadata/RelationPropertyMetadata.php ) we use inherits from PropertyMetadata ... so I don't see why that'd be an issue. |
Well i can give an exemple, on the first gist I only use jmsserializer and the output with maxDepth = 1 is what i expected: https://gist.github.com/yoye/8470702 {
"username": "foo",
"friend": {
"username": "bar"
}
} But with hateoas lib i've got the following result: https://gist.github.com/yoye/8470772 {
"username": "foo",
"_embedded": {
"friend": {
"username": "bar",
"_embedded": {
"friend": {
"username": "foobar",
"_embedded": {
"friend": {
"username": "baz",
"_embedded": {
"friend": null
}
}
}
}
}
}
}
} Did I misunderstand MaxDepth usage ? |
So what is the status of this issue? ping @adrienbrault |
There seems to be an issue, because the max depth exclusion strategy uses the serialization context stack, but the embedded objects metadata never get into the stack. |
Hi, I just stumbled upon this problem. What is the status of this issue? |
I've prototyped adrienbrault@1dd946b which fixes the issue in your example. However that's breaking tests and that has a very bad design. I'm trying to see what I can do. |
A slightly better architecture adrienbrault@85824b4 I will see what I can change on the serializer to make this implementation easier/cleaner. |
This problem affects me too. Could you say if you already have a solution? |
@adrienbrault, could you tell us what is the status of the bug? |
Any news here? |
@wodka I don't think it will ever be fixed. We will try to migrate away from this lib soon. |
@mhert you know an alternative or a fork where this has been fixed? |
@wodka Unfortunately not |
Did you try this patch? adrienbrault@85824b4 |
I tried just now (just applied the changes to the current master)
Sadly it now just stops at already serialized elements - it completely ignores the maxDepth setting. |
ok, I missed one thing: if using FOSRestBundle it is required in annotation:
further the Exclusion has to be defined inside the Embedded annotation and not in the Relation annotation.
After moving the Metadata push before the embedded / link creation it seems to work. :) to try:in composer override the repositories:
and force the master branch:
If this is working for others as well - I'd create a pull request. |
Don't work for me |
@neiron486k Hi. This work, just checked. This you should add to your controller: This you should add to your entity:
One of my problems was that I've added
So maybe you have same issue. Read docs one more time - this helped me :) |
Hi everyone.
Sylius\Component\User\Model\Customer:
exclusion_policy: ALL
xml_root_name: sylius_customer
properties:
id:
expose: true
type: integer
groups: [Default, Detailed]
email:
expose: true
type: string
groups: [Detailed]
emailCanonical:
expose: true
type: string
groups: [Default, Detailed]
firstName:
expose: true
type: string
groups: [Default, Detailed]
lastName:
expose: true
type: string
groups: [Default, Detailed]
gender:
expose: true
type: string
groups: [Detailed]
birthday:
expose: true
type: DateTime
groups: [Detailed]
groups:
expose: true
type: array
groups: [Detailed]
relations:
- rel: user
href:
route: sylius_api_user_show
parameters:
id: expr(object.getUser().getId())
embedded:
content: expr(object.getUser())
xmlElementName: sylius_user
exclusion:
exclude_if: expr(object.getUser() === null)
Sylius\Component\User\Model\User:
exclusion_policy: ALL
xml_root_name: sylius_user
properties:
id:
expose: true
type: integer
groups: [Default, Detailed]
username:
expose: true
type: string
groups: [Default, Detailed]
usernameCanonical:
expose: true
type: string
groups: [Detailed]
enabled:
expose: true
type: boolean
groups: [Default, Detailed]
roles:
expose: true
type: array
groups: [Detailed] The configuration I thought would solve the problem looked like this:
Sylius\Component\User\Model\Customer:
exclusion_policy: ALL
xml_root_name: sylius_customer
properties:
id:
expose: true
type: integer
groups: [Default, Detailed]
email:
expose: true
type: string
groups: [Detailed]
emailCanonical:
expose: true
type: string
groups: [Default, Detailed]
firstName:
expose: true
type: string
groups: [Default, Detailed]
lastName:
expose: true
type: string
groups: [Default, Detailed]
gender:
expose: true
type: string
groups: [Detailed]
birthday:
expose: true
type: DateTime
groups: [Detailed]
groups:
expose: true
type: array
groups: [Detailed]
relations:
- rel: user
href:
route: sylius_api_user_show
parameters:
id: expr(object.getUser().getId())
embedded:
content: expr(object.getUser())
xmlElementName: sylius_user
exclusion:
max_depth: 1
exclusion:
exclude_if: expr(object.getUser() === null)
Sylius\Component\User\Model\User:
exclusion_policy: ALL
xml_root_name: sylius_user
properties:
id:
expose: true
type: integer
groups: [Default, Detailed]
username:
expose: true
type: string
groups: [Detailed]
usernameCanonical:
expose: true
type: string
groups: [Default, Detailed]
enabled:
expose: true
type: boolean
groups: [Default, Detailed]
roles:
expose: true
type: array
groups: [Detailed]
relations:
- rel: user
href:
route: sylius_api_customer_show
parameters:
id: expr(object.getCustomer().getId())
embedded:
content: expr(object.getCustomer())
xmlElementName: sylius_customer
exclusion:
max_depth: 1 Do you have any solution for that or any idea for some workaround? |
this should be solved with #246 |
Thanks @goetas! |
It seem's that MaxDepth exclusion strategy does not work. At the moment in jms-serializer it can only be tested if metadata is an instance of PropertyMetadata
https://github.com/schmittjoh/serializer/blob/master/src/JMS/Serializer/Exclusion/DepthExclusionStrategy.php#L55
But Exclusion can only be defined in class annotation.
The text was updated successfully, but these errors were encountered: