/**
  * @param \stdObject $jsonObject
  * @param ModelFactoryInterface $factory
  *
  * @return $this
  */
 public function parseJson($jsonObject, ModelFactoryInterface $factory)
 {
     $this->categories = array();
     $this->parentChildIds = array();
     if (isset($jsonObject->parent_child)) {
         // this hack converts the array keys to integers, otherwise $this->parentChildIds[$id] fails
         $this->parentChildIds = json_decode(json_encode($jsonObject->parent_child), true);
         foreach ($jsonObject->ids as $id => $jsonCategory) {
             $this->categories[$id] = $factory->createCategory($jsonCategory, $this);
         }
     }
     $this->cacheCategories();
     return $this;
 }
 /**
  * parse autocompleted categories.
  *
  *
  * @param \stdClass $jsonObject
  * @param ModelFactoryInterface $factory
  *
  * @return Category[]|null
  */
 protected static function parseCategories(\stdClass $jsonObject, ModelFactoryInterface $factory)
 {
     if (!property_exists($jsonObject, 'categories')) {
         return self::NOT_REQUESTED;
     }
     if ($jsonObject->categories === null) {
         return array();
     }
     $categories = array();
     foreach ($jsonObject->categories as $category) {
         $categories[] = $factory->createCategory($category);
     }
     return $categories;
 }