From 120aaf249dbd97a25757015754a5bb705d50b44d Mon Sep 17 00:00:00 2001 From: An Tao Date: Sun, 26 Mar 2023 17:03:19 +0800 Subject: [PATCH] Remove the deprecated Json::Reader (#1546) --- lib/src/JsonConfigAdapter.cc | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/src/JsonConfigAdapter.cc b/lib/src/JsonConfigAdapter.cc index 2647dfb9..3505ac7d 100644 --- a/lib/src/JsonConfigAdapter.cc +++ b/lib/src/JsonConfigAdapter.cc @@ -1,15 +1,21 @@ #include "JsonConfigAdapter.h" #include +#include using namespace drogon; Json::Value JsonConfigAdapter::getJson(const std::string &content) const noexcept(false) { + static std::once_flag once; + static Json::CharReaderBuilder builder; + std::call_once(once, []() { builder["collectComments"] = false; }); + JSONCPP_STRING errs; + std::unique_ptr reader(builder.newCharReader()); Json::Value root; - Json::Reader reader; - if (!reader.parse(content, root)) + if (!reader->parse( + content.c_str(), content.c_str() + content.size(), &root, &errs)) { - throw std::runtime_error("Failed to parse JSON"); + throw std::runtime_error(errs); } return root; }