--------------------------------- VariantToJsonValue Recursively convert an rttr::variant to a json value, figuring out it's type in the process
| 79 | // Recursively convert an rttr::variant to a json value, figuring out it's type in the process |
| 80 | // |
| 81 | bool VariantToJsonValue(rttr::variant const& var, JSON::Value*& outVal) |
| 82 | { |
| 83 | rttr::type valueType = var.get_type(); |
| 84 | rttr::type wrappedType = valueType.is_wrapper() ? valueType.get_wrapped_type() : valueType; |
| 85 | bool isWrapper = wrappedType != valueType; |
| 86 | |
| 87 | if (AtomicTypeToJsonValue(wrappedType, isWrapper ? var.extract_wrapped_value() : var, outVal)) |
| 88 | { |
| 89 | // check here if this was a nullptr, if it wasn't and the JSON object is of type JSON_Null we should return false |
| 90 | } |
| 91 | else if (var.is_sequential_container()) |
| 92 | { |
| 93 | if (!ArrayToJsonArray(var.create_sequential_view(), outVal)) |
| 94 | { |
| 95 | LOG("VariantToJsonValue > Failed to convert variant to json array, typeName: '" + wrappedType.get_name().to_string() |
| 96 | + std::string("'!"), LogLevel::Warning); |
| 97 | |
| 98 | return false; |
| 99 | } |
| 100 | } |
| 101 | else if (var.is_associative_container()) |
| 102 | { |
| 103 | if (!AssociativeContainerToJsonArray(var.create_associative_view(), outVal)) |
| 104 | { |
| 105 | LOG("VariantToJsonValue > Failed to convert variant to associate view, typeName: '" + wrappedType.get_name().to_string() |
| 106 | + std::string("'!"), LogLevel::Warning); |
| 107 | |
| 108 | return false; |
| 109 | } |
| 110 | } |
| 111 | else |
| 112 | { |
| 113 | if (!ToJsonRecursive(var, outVal, wrappedType)) |
| 114 | { |
| 115 | LOG("VariantToJsonValue > Failed to convert variant to JSON object, typeName: '" + wrappedType.get_name().to_string() |
| 116 | + std::string("'!"), LogLevel::Warning); |
| 117 | |
| 118 | return false; |
| 119 | } |
| 120 | //if (!(wrappedType.get_properties().empty())) // try converting the variant to a JSON object |
| 121 | //{ |
| 122 | //} |
| 123 | //else // if that fails, try converting it to a string |
| 124 | //{ |
| 125 | // bool stringConversionSuccess = false; |
| 126 | // std::string text = var.to_string(&stringConversionSuccess); |
| 127 | |
| 128 | // if (!stringConversionSuccess) |
| 129 | // { |
| 130 | // LOG("VariantToJsonValue > Failed to convert variant to JSON string, result: '" + text + std::string("' typeName: '") |
| 131 | // + wrappedType.get_name().to_string() + std::string("'!"), LogLevel::Warning); |
| 132 | |
| 133 | // return false; |
| 134 | // } |
| 135 | |
| 136 | // outVal = new JSON::String(); |
| 137 | // outVal->str()->value = text; |
| 138 | //} |
no test coverage detected