-
Notifications
You must be signed in to change notification settings - Fork 349
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
Paginator links property is either empty array or filled object #433
Comments
I also have this issue. It would be nice if it was consistent and always returned an object for the As @tomvo mentioned it looks like this could be solved with a one line change in Change from: $pagination['links'] = []; to $pagination['links'] = new \ArrayObject(); |
I agree with this, One of our App guys has issues when consuming this with Swift. Is there a reason this cannot be fixed since it appears to be quite trivial? |
It appears to be quite trivial until you see under the hood, this is using associative arrays. Because of that, its very difficult to determine if an empty array is an empty associative array or an empty object. I did try to do a fix for this over a year ago using I will revisit this, it is a known issue and one we’ve been pondering for way to long now. |
Ignore me, I was talking about this issue for empty objects in the data namespace. Everywhere that data is created, it creates it as an empty array. Fixing that issue creates problems. Fixing this issue does not, in my opinion. If you’ve written code to treat an empty array as an empty object, and you get an empty object, would that cause breaking changes? Only if somebody is relying on a property being an array to determine if an object is empty. How likely is that? I would love to fix this but it’d probably need a major version bump to appease people who have hacked in workarounds that would break with the fix, but then it’s not worth doing this fix without the other How about… I add another serializer: |
just hit the same issue when testing our OpenAPI specs against the API output. Would love to see an empty object here as well 👍 |
I have solved this by extending the |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 4 weeks if no further activity occurs. Thank you for your contributions. |
As per this question in a wrapper library spatie/fractalistic#36 (comment), I'm noticing difference in the response for the
ArraySerializer
for when the pagination has links or not.When there are no links for the pagination the meta property looks like this:
When there are, it looks like this:
You can see that in an empty resultset the
links
property is an array and when set, it's an object. This causes issues for devices consuming our API.This issue is caused by the default
ArraySerializer
creating the links property as an empty array ([]
), see here: https://github.com/thephpleague/fractal/blob/master/src/Serializer/ArraySerializer.php#L105.The solution to this would be to create an empty
ArrayObject
instead of a normalArray
.Of course I can fix this for my case with overloading the
paginator
method but would you accept a tested PR for this or is this too breaking?The text was updated successfully, but these errors were encountered: