* @brief parses json content and returns the parsed json or throws. * @param jsonContent json content to parse as a std::istream. * @param root The parsed Json root object. * @throw InvalidManifest if the json is invalid. Parse error information is in the exception. * If an exception is thrown, the root param is invalid. */
| 186 | * If an exception is thrown, the root param is invalid. |
| 187 | */ |
| 188 | void |
| 189 | parseAndValidateJson(std::istream& jsonContent, rapidjson::Document& root) |
| 190 | { |
| 191 | rapidjson::IStreamWrapper stream(jsonContent); |
| 192 | root.ParseStream(stream); |
| 193 | |
| 194 | if (root.HasParseError()) |
| 195 | { |
| 196 | std::string errs = std::string("Offset ") + std::to_string(root.GetErrorOffset()) + ": " |
| 197 | + rapidjson::GetParseError_En(root.GetParseError()); |
| 198 | throw InvalidManifest(errs); |
| 199 | } |
| 200 | |
| 201 | try |
| 202 | { |
| 203 | cppmicroservices::rapidjsonutils::checkDuplicateKeys(root); |
| 204 | } |
| 205 | catch (std::runtime_error const& e) |
| 206 | { |
| 207 | throw InvalidManifest(e.what()); |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | /* |
| 212 | * @brief parses json content from a file and returns the parsed json or throws. |
no test coverage detected