public static function fillFromJSON($model, $json, $isError=false) {
        if(is_array($json)) {
            $array = $json;
        } else {
            if (get_magic_quotes_gpc()) {
                $json = stripslashes($json);
            }
            $array = json_decode($json, true);
        }

        if(!is_array($array))
            $array = array();

        if($isError) {
            $exception = self::createFromJSON('infobip\models\SmsException', $json, false);
            $model->exception = $exception;
            return $model;
        }

        $conversionRules = Models::getConversionRules(get_class($model));

        $className = get_class($model);

        // Keep original JSON values (for simple string values):
        foreach($array as $key => $value) {
            if(property_exists($className, $key) && (is_string($value) || is_numeric($value) || is_bool($value))) {
                $model->$key = $value;
            }
        }

        // Convert the ones that have custom conversion rules:
        foreach($conversionRules as $conversionRule) {
            foreach($array as $key => $value) {
                if($conversionRule instanceof FieldConversionRule) {
                    // field conversion rule:
                    if(property_exists($className, $key) && $conversionRule->field == $key) {
                        $model->$key = $conversionRule->convertFromJSON($value);
                    }
                }
            }
        }
        foreach($conversionRules as $conversionRule) {
            if($conversionRule instanceof ObjectConversionRule) {
                $conversionRule->convertFromJson($model, $array);
            }
        }

        return $model;
    }