diff --git a/src/utils/monero_utils.cpp b/src/utils/monero_utils.cpp index b7a63cf..07279a6 100644 --- a/src/utils/monero_utils.cpp +++ b/src/utils/monero_utils.cpp @@ -452,11 +452,13 @@ string monero_utils::serialize(const boost::property_tree::ptree& node) { } // TODO: switch deserializes in this utils class to use this deserialize util -boost::property_tree::ptree monero_utils::deserialize(const string& json) { +void monero_utils::deserialize(const string& json, boost::property_tree::ptree& root) { std::istringstream iss = json.empty() ? std::istringstream() : std::istringstream(json); - boost::property_tree::ptree node; - boost::property_tree::read_json(iss, node); - return node; + try { + boost::property_tree::read_json(iss, root); + } catch (std::exception const& e) { + throw runtime_error("Invalid JSON"); + } } boost::property_tree::ptree monero_utils::to_property_tree(const vector& strs) { diff --git a/src/utils/monero_utils.h b/src/utils/monero_utils.h index 2442002..1c63783 100644 --- a/src/utils/monero_utils.h +++ b/src/utils/monero_utils.h @@ -84,7 +84,7 @@ namespace monero_utils string serialize(const boost::property_tree::ptree& node); - boost::property_tree::ptree deserialize(const string& json); + void deserialize(const string& json, boost::property_tree::ptree& root); /** * Convert a Monero Core cryptonote::block to a block in this library's native model.