protected function checkType($value, $type, $allowedClassNames, $errorCode)
    {
        //We only accept object of array
        if ($type && $value && gettype($value) != $type)
            throw new WebServiceException("Should be a $type"
                                         .", but it's a " . gettype($value), $errorCode);

        if (!$value && count($allowedClassNames) >0) {
            throw new WebServiceException("Should a instance of "
                                         . $this->_getAllowedClassNameString($allowedClassNames)
                                         .", but it's null ", $errorCode);
        }

        //check if the value implement JsonSerializable if needed
        if ($this->needToImplementJsonSerializable($value) &&
            !($value instanceof JsonSerializable)) {
            throw new WebServiceException("object of type ".get_class($value)." has to implement "
                                         ."PureMachine\Bundle\SDKBundle\Store\JsonSerializable "
                                         ."Interface",
                                          $errorCode);
        }

        //If value is store, we validate it
        if ($value instanceof BaseStore) {
            //Check if the type if fine if defined
            if(count($allowedClassNames) >0 &&
               !in_array(get_class($value), $allowedClassNames)) {
                throw new WebServiceException("your store should be a intance of "
                                             . $this->_getAllowedClassNameString($allowedClassNames)
                                             .", but it's a " . get_class($value),
                                             $errorCode);
            }

            //Validate the store
            if (!$value->validate($this->getValidator())) {
                $violations = $value->getViolations();
                $property = $violations[0]->getPropertyPath();
                $message = $value->getFirstErrorString();
                throw new WebServiceException($message, $errorCode);
            }
        //We have an array of object, and potentiallt stores
        //We need to check the type and validate stores
        } elseif ($type == 'array' && is_array($allowedClassNames) && count($allowedClassNames) > 0) {
            foreach ($value as $store) {
                $this->checkType($store, 'object', $allowedClassNames, $errorCode);
            }
        }
    }