Closed BradGriffith closed 1 year ago
Note the above is for package version 1.01. I get similar errors in 3.2 but the line numbers are different.
InvalidArgumentException JsonMapper::map() requires first argument to be an object, array given.
apimatic/jsonmapper/src/JsonMapper.php:103 apimatic/jsonmapper/src/JsonMapper.php:270 apimatic/jsonmapper/src/JsonMapper.php:322 vendor/pipedrive/pipedrive/src/Controllers/DealsController.php:396
I believe I've found a solution for this that's a very simple change in the GetDealsTimeline model to indicate that the data is an array of Data25 objects, not just a single Data25 object.
--- a/src/Models/GetDealsTimeline.php
+++ b/src/Models/GetDealsTimeline.php
@@ -23,14 +23,14 @@ class GetDealsTimeline implements JsonSerializable
/**
* Open and won Deals grouped into periods by defined interval, amount and date-type dealField
* (field_key)
- * @var \Pipedrive\Models\Data25|null $data public property
+ * @var \Pipedrive\Models\Data25[]|null $data public property
*/
public $data;
/**
* Constructor to set initial or default values of member properties
* @param bool $success Initialization value for $this->success
- * @param Data25 $data Initialization value for $this->data
+ * @param Data25[] $data Initialization value for $this->data
*/
public function __construct()
{
I opened a pull request for this change (see above)
Hi! Thanks for the solution! I'm checking open PRs, one of them was related to this issue. The issue was solved on this commit: https://github.com/pipedrive/client-php/commit/7734d2075183c589899d7dd9e04bd07e3fa0a4bc
InvalidArgumentException JsonMapper::map() requires first argument to be an object, array given. in vendor/apimatic/jsonmapper/src/JsonMapper.php:103
It looks like the getDealsTimeline API response returns an object with the data member as an array for like this:
When jsonmapper tries to map this response in
pipedrive/pipedrive/src/Controllers/DealsController.php:459
the data ends up being recognized as an object of type\Pipedrive\Models\Data25
rather than as an array. But inapimapper/jsonmapper/src/JsonMapper.php:103
an InvalidArgumentException is thrown because$json
that is passed in is an array rather than an object.Ultimately, I think JsonMapper should be calling
mapArray
ormapClassArray
aroundJsonMapper.php:247
but it is instead trying to callmap
which only works with an object.I wish I could have determined the root cause here to provide a merge request to fix this, but the best I could come up with is to skip using JsonMapper and to instead just return the object that comes back from the API. This looks like:
That solution neglects whatever value JsonMapper has.
Thanks for your help troubleshooting and fixing this issue!