davidtsadler / ebay-sdk-php

An eBay SDK for PHP. Use the eBay API in your PHP projects.
Apache License 2.0
349 stars 341 forks source link

Serialize from/to json #242

Closed albertixcom closed 4 years ago

albertixcom commented 5 years ago

Hi I've try to make my own cache of products list using json, so I've made this:

/*@var $items Types\ItemType[] */
$items = $trading->getMyeBaySellingItems();
foreach($items As $item) {
  $string = json_encode($item->toArray(), JSON_PRETTY_PRINT);
  $arr = json_decode($string, true);

  //---- GOT ERROR: 
  // Types\BaseType private on
  //  function set($class, $name, $value) 
  // self::ensurePropertyType($class, $name, $value); 
  $testItem = new Types\ItemType($arr);
}

This error is because: Array ( [BuyItNowPrice] => Array ( [value] => 179 // Value in json is Integer, expected double

Temporary solution:

// self::ensurePropertyType($class, $name, $value);

I suggest to create adjust "toArray" function with vars like this: 179.0 so interpreted recognize it like double and not integer

Sorry for my horrible english. Alberto