Serialize tool capabilities JSON without whitespace

fixes #11087
This commit is contained in:
sfan5 2021-03-20 22:06:17 +01:00
parent 042131d91d
commit 531e7ef8eb
3 changed files with 13 additions and 4 deletions

@ -68,12 +68,17 @@ Json::Value fetchJsonValue(const std::string &url,
return root; return root;
} }
std::string fastWriteJson(const Json::Value &value) void fastWriteJson(const Json::Value &value, std::ostream &to)
{ {
std::ostringstream oss;
Json::StreamWriterBuilder builder; Json::StreamWriterBuilder builder;
builder["indentation"] = ""; builder["indentation"] = "";
std::unique_ptr<Json::StreamWriter> writer(builder.newStreamWriter()); std::unique_ptr<Json::StreamWriter> writer(builder.newStreamWriter());
writer->write(value, &oss); writer->write(value, &to);
}
std::string fastWriteJson(const Json::Value &value)
{
std::ostringstream oss;
fastWriteJson(value, oss);
return oss.str(); return oss.str();
} }

@ -20,8 +20,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#pragma once #pragma once
#include <json/json.h> #include <json/json.h>
#include <ostream>
Json::Value fetchJsonValue(const std::string &url, Json::Value fetchJsonValue(const std::string &url,
std::vector<std::string> *extra_headers); std::vector<std::string> *extra_headers);
void fastWriteJson(const Json::Value &value, std::ostream &to);
std::string fastWriteJson(const Json::Value &value); std::string fastWriteJson(const Json::Value &value);

@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "log.h" #include "log.h"
#include "inventory.h" #include "inventory.h"
#include "exceptions.h" #include "exceptions.h"
#include "convert_json.h"
#include "util/serialize.h" #include "util/serialize.h"
#include "util/numeric.h" #include "util/numeric.h"
@ -142,7 +143,7 @@ void ToolCapabilities::serializeJson(std::ostream &os) const
} }
root["damage_groups"] = damage_groups_object; root["damage_groups"] = damage_groups_object;
os << root; fastWriteJson(root, os);
} }
void ToolCapabilities::deserializeJson(std::istream &is) void ToolCapabilities::deserializeJson(std::istream &is)