static int jsonSerializer_parseAny()

in libs/dfi/src/json_serializer.c [124:241]


static int jsonSerializer_parseAny(const dyn_type* type, void* loc, json_t* val) {
    int status = OK;

    const dyn_type* subType = NULL;
    char c = dynType_descriptorType(type);

    switch (c) {
        case 'Z' :
            *(bool*)loc = (bool) json_is_true(val);
            break;
        case 'F' :
            *(float*)loc = (float) json_real_value(val);
            break;
        case 'D' :
            *(double*)loc = json_real_value(val);
            break;
        case 'N' :
            *(int*)loc = (int) json_integer_value(val);
            break;
        case 'B' :
            *(char*)loc = (char) json_integer_value(val);
            break;
        case 'S' :
            *(int16_t*)loc = (int16_t) json_integer_value(val);
            break;
        case 'I' :
            *(int32_t*)loc = (int32_t) json_integer_value(val);
            break;
        case 'J' :
            *(int64_t*)loc = (int64_t) json_integer_value(val);
            break;
        case 'b' :
            *(uint8_t*)loc = (uint8_t) json_integer_value(val);
            break;
        case 's' :
            *(uint16_t*)loc = (uint16_t) json_integer_value(val);
            break;
        case 'i' :
            *(uint32_t*)loc = (uint32_t) json_integer_value(val);
            break;
        case 'j' :
            *(uint64_t*)loc = (uint64_t) json_integer_value(val);
            break;
        case 'E' :
            if (json_is_string(val)){
                status = jsonSerializer_parseEnum(type, json_string_value(val), loc);
            } else {
                status = ERROR;
                celix_err_pushf("Expected json string for enum type but got %i", json_typeof(val));
            }
            break;
        case 't' :
            if (json_is_null(val)) {
                // NULL string is allowed
            } else if (json_is_string(val)) {
                status = dynType_text_allocAndInit(type, loc, json_string_value(val));
            } else {
                status = ERROR;
                celix_err_pushf("Expected json string type got %i", json_typeof(val));
            }
            break;
        case 'p':
            if (json_is_null(val)) {
                // NULL celix_properties_t* is allowed
            } else if (json_is_object(val)) {
                status = jsonSerializer_parseProperties(type, val, loc);
            } else {
                status = ERROR;
                celix_err_pushf("Expected json object for celix_properties_t* type but got %i", json_typeof(val));
            }
            break;
        case 'a':
            if (json_is_null(val)) {
                // NULL celix_array_list_t* is allowed
            } else if (json_is_array(val)) {
                status = jsonSerializer_parseArrayList(type, val, loc);
            } else {
                status = ERROR;
                celix_err_pushf("Expected json array for celix_array_list_t* type but got %i", json_typeof(val));
            }
            break;
        case '[' :
            if (json_is_array(val)) {
                status = jsonSerializer_parseSequence(type, val, loc);
            } else {
                status = ERROR;
                celix_err_pushf("Expected json array type got '%i'", json_typeof(val));
            }
            break;
        case '{' :
            if (json_is_object(val)) {
                status = jsonSerializer_parseObject(type, val, loc);
            } else {
                status = ERROR;
                celix_err_pushf("Expected json object type got '%i'", json_typeof(val));
            }
            break;
        case '*' :
            subType = dynType_typedPointer_getTypedType(type);
            if (dynType_ffiType(subType) != &ffi_type_pointer) {
                // NULL pointer is allowed
                if (!json_is_null(val)) {
                    status = jsonSerializer_createType(subType, val, (void **) loc);
                }
            } else {
                status = ERROR;
                celix_err_pushf("Error cannot deserialize pointer to pointer");
            }
            break;
        //case 'P' :
        default :
            status = ERROR;
            celix_err_pushf("Error provided type '%c' not supported for JSON\n", c);
            break;
    }

    return status;
}