in libs/utils/src/celix_array_list_encoding.c [43:96]
static celix_status_t celix_arrayList_determineArrayType(const json_t* jsonArray,
celix_array_list_element_type_t* out) {
assert(json_array_size(jsonArray) > 0); //precondition: size > 0
json_t* value;
int index;
json_type type = JSON_NULL;
bool versionType = false;
json_array_foreach(jsonArray, index, value) {
if (index == 0) {
type = json_typeof(value);
if (type == JSON_STRING && celix_utils_isVersionJsonString(value)) {
versionType = true;
}
} else if ((type == JSON_TRUE || type == JSON_FALSE) && json_is_boolean(value)) {
// bool, ok.
continue;
} else if (type == JSON_INTEGER && json_typeof(value) == JSON_REAL) {
// mixed integer and real, ok but promote to real
type = JSON_REAL;
continue;
} else if (type == JSON_REAL && json_typeof(value) == JSON_INTEGER) {
// mixed real and integer, ok
continue;
} else if (type != json_typeof(value)) {
return CELIX_ILLEGAL_ARGUMENT;
} else if (versionType) {
if (json_typeof(value) != JSON_STRING || !celix_utils_isVersionJsonString(value)) {
return CELIX_ILLEGAL_ARGUMENT;
}
}
}
switch (type) {
case JSON_STRING:
*out = versionType ? CELIX_ARRAY_LIST_ELEMENT_TYPE_VERSION : CELIX_ARRAY_LIST_ELEMENT_TYPE_STRING;
break;
case JSON_INTEGER:
*out = CELIX_ARRAY_LIST_ELEMENT_TYPE_LONG;
break;
case JSON_REAL:
*out = CELIX_ARRAY_LIST_ELEMENT_TYPE_DOUBLE;
break;
case JSON_TRUE:
case JSON_FALSE:
*out = CELIX_ARRAY_LIST_ELEMENT_TYPE_BOOL;
break;
default:
//JSON_NULL, JSON_OBJECT and JSON_ARRAY
return CELIX_ILLEGAL_ARGUMENT;
}
return CELIX_SUCCESS;
}