-
Notifications
You must be signed in to change notification settings - Fork 48
Solves json_encode problem. When an external thing (like a script or … #206
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
Conversation
…framework) not calling toJson method, json is returned empty
That's strange. When you do arangodb-php/tests/DocumentBasicTest.php Line 473 in 1ebef03
Could you elaborate on your scenario? |
I am using Silex framework and retrieving information from arango to a Web API. When I send my resultset to the JsonResponse, the data is missing, all objects seem empty. See the example: I have three documents. When I try json_encode($cursor->getAll(), the response is: Changing the Document class and implementing JsonSerializable, this problem is solved. |
Oh, I see. Yes. From a quick look at Silex's JsonResponse class, it expects an array or an object which would provide its data as public properties. Since the document object does not have any public properties (as the data is stored inside a protected one) the result-set is comprised of empty JSON objects. @jsteemann It seems that indeed implementing JsonSerializable is the easiest way to go, here. |
@frankmayer: it would be quite nice if one could configure the driver to return either |
@jsteemann I think, it would be doable with reasonable effort. I'll have a look and get back. |
@jsteemann, I think JsonSerializable should be implemented as a first solution and a better solution can come after. The @frankmayer's idea is good: choose a parameter that changes the way of return data (documents or array). |
It turns out, there was already an option built-in for this. @evaldobarbosa If you take a look at this test (https://github.com/arangodb/arangodb-php/blob/devel/tests/CollectionExtendedTest.php#L797), you will see that passing the option Please understand that I am a bit cautious in changing this kind of things (like implementing the JsonSerializable interface), especially when they have a performance impact, because this is a driver. |
@frankmayer, see this example. |
@evaldobarbosa ok, installation took a bit longer as I had to first create the config.json in the private folder ;)
Maybe you have some different code in your actual setup, where id doesn't work? |
@evaldobarbosa BTW, this is what I got from getting all documents:
|
…framework) not calling toJson method, json is returned empty