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

Allow getting raw results of an API Response #182

Open
MurzNN opened this issue Jun 14, 2024 · 2 comments
Open

Allow getting raw results of an API Response #182

MurzNN opened this issue Jun 14, 2024 · 2 comments

Comments

@MurzNN
Copy link
Contributor

MurzNN commented Jun 14, 2024

Is your feature request related to a problem? Please describe.
I need to get the full raw results of an API response.
In v1 it was possible via function $response->toArray():

$response = $request->execute();
$responseData = $response->toArray();

But in v2 this method is marked as protected in lib/commercetools-base/src/Base/JsonObjectModel.php:

    final protected function toArray(): array

So we can't get the raw results by this method.

Describe the solution you'd like
Is there any other way to get the raw response as an array, like in v1?
If not, could you please consider making this method public in v2, like in v1?

Describe alternatives you've considered
Alternatively, maybe it's good to provide another method to get raw results if you don't want to make the current toArray public for some reason?

@MurzNN
Copy link
Contributor Author

MurzNN commented Jun 18, 2024

Seems we can use the jsonSerialize() method to get the raw data of the response, is it right?

$response = $request->execute();
$responseData = (array) $response->jsonSerialize();

@jenschude
Copy link
Contributor

jenschude commented Jun 18, 2024

This would still deserialize the response using json_deserialize. The jsonSerialize method would then convert the result to a serializable representation.

You could save the step by just using $request->send() as it would return the response with the raw string in the body.

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

2 participants