fix - ensure stringifier called recursively for nested json objects

This commit is contained in:
artemp 2016-11-18 09:42:47 +01:00
parent e6e468dc9e
commit ead152499b

View file

@ -36,6 +36,9 @@ namespace mapnik { namespace json {
struct stringifier struct stringifier
{ {
stringifier(keys_map const& keys)
: keys_(keys) {}
std::string operator()(std::string const& val) const std::string operator()(std::string const& val) const
{ {
return "\"" + val + "\""; return "\"" + val + "\"";
@ -79,14 +82,14 @@ struct stringifier
return str; return str;
} }
std::string operator()(mapnik::json::geojson_object const& object, keys_map const& keys) const std::string operator()(mapnik::json::geojson_object const& object) const
{ {
std::string str = "{"; std::string str = "{";
bool first = true; bool first = true;
for (auto const& kv : object) for (auto const& kv : object)
{ {
auto itr = keys.right.find(std::get<0>(kv)); auto itr = keys_.right.find(std::get<0>(kv));
if (itr != keys.right.end()) if (itr != keys_.right.end())
{ {
if (first) first = false; if (first) first = false;
else str += ","; else str += ",";
@ -103,6 +106,8 @@ struct stringifier
{ {
return ""; return "";
} }
keys_map const& keys_;
}; };
struct attribute_value_visitor struct attribute_value_visitor
@ -119,13 +124,13 @@ public:
mapnik::value operator()(mapnik::json::geojson_array const& array) const mapnik::value operator()(mapnik::json::geojson_array const& array) const
{ {
std::string str = stringifier()(array); std::string str = stringifier(keys_)(array);
return mapnik::value(tr_.transcode(str.c_str())); return mapnik::value(tr_.transcode(str.c_str()));
} }
mapnik::value operator()(mapnik::json::geojson_object const& object) const mapnik::value operator()(mapnik::json::geojson_object const& object) const
{ {
std::string str = stringifier()(object, keys_); std::string str = stringifier(keys_)(object);
return mapnik::value(tr_.transcode(str.c_str())); return mapnik::value(tr_.transcode(str.c_str()));
} }