diff --git a/SimoxUtility/CMakeLists.txt b/SimoxUtility/CMakeLists.txt index 24d09bcc300b2a055286470d1b181aa71a094d8e..b39459da876abe4caebf4d4c65af2b4b22101683 100644 --- a/SimoxUtility/CMakeLists.txt +++ b/SimoxUtility/CMakeLists.txt @@ -24,6 +24,7 @@ SET(SOURCES filesystem/list_directory.cpp json/eigen_conversion.cpp + json/error.cpp json/io.cpp json/converters.cpp json/util.cpp @@ -97,8 +98,10 @@ SET(INCLUDES json.h json/converters.h json/eigen_conversion.h + json/error.h json/io.h json/json.hpp + json/json.h json/util.h diff --git a/SimoxUtility/json.h b/SimoxUtility/json.h index c3d4f4fef9452bd345f59ec0ced7d3d2596da813..12b196591ca2ade994129aa50b2ac8f031dfa30b 100644 --- a/SimoxUtility/json.h +++ b/SimoxUtility/json.h @@ -4,5 +4,7 @@ #include "json/converters.h" #include "json/eigen_conversion.h" +#include "json/error.h" #include "json/io.h" +#include "json/json.h" #include "json/util.h" diff --git a/SimoxUtility/json/converters.cpp b/SimoxUtility/json/converters.cpp index 9f3b234c4d5bdbe27c69b5af7b38013f4f085701..acd8f1e00824149848112a2088657bd586d48095 100644 --- a/SimoxUtility/json/converters.cpp +++ b/SimoxUtility/json/converters.cpp @@ -7,11 +7,11 @@ namespace simox { Eigen::Matrix4f json::posquat2eigen4f(const std::string& str) { - return posquat2eigen4f(::nlohmann::json::parse(str)); + return posquat2eigen4f(::simox::json::json::parse(str)); } Eigen::Matrix4f json::posquat2eigen4f(const char* str) { - return posquat2eigen4f(::nlohmann::json::parse(str)); + return posquat2eigen4f(::simox::json::json::parse(str)); } Eigen::Matrix4f json::posquat2eigen4f(const nlohmann::json& j) { @@ -28,11 +28,11 @@ namespace simox std::vector<Eigen::Matrix4f> json::posquatArray2eigen4fVector(const std::string& str) { - return posquatArray2eigen4fVector(::nlohmann::json::parse(str)); + return posquatArray2eigen4fVector(::simox::json::json::parse(str)); } std::vector<Eigen::Matrix4f> json::posquatArray2eigen4fVector(const char* str) { - return posquatArray2eigen4fVector(::nlohmann::json::parse(str)); + return posquatArray2eigen4fVector(::simox::json::json::parse(str)); } std::vector<Eigen::Matrix4f> json::posquatArray2eigen4fVector(const nlohmann::json& j) @@ -90,11 +90,11 @@ namespace simox std::map<std::string, float> json::json2NameValueMap(const std::string& str) { - return json2NameValueMap(::nlohmann::json::parse(str)); + return json2NameValueMap(::simox::json::json::parse(str)); } std::map<std::string, float> json::json2NameValueMap(const char* str) { - return json2NameValueMap(::nlohmann::json::parse(str)); + return json2NameValueMap(::simox::json::json::parse(str)); } std::map<std::string, float> json::json2NameValueMap(const nlohmann::json& j) { diff --git a/SimoxUtility/json/converters.h b/SimoxUtility/json/converters.h index 34c778c19009ca0c8839c9bbe5254d3e38b077db..8f1a65023656213f591b10f37ab8f4a4501f221b 100644 --- a/SimoxUtility/json/converters.h +++ b/SimoxUtility/json/converters.h @@ -5,23 +5,23 @@ #include <Eigen/Core> -#include "json.hpp" +#include "json.h" namespace simox::json { Eigen::Matrix4f posquat2eigen4f(const std::string& str); Eigen::Matrix4f posquat2eigen4f(const char* str); - Eigen::Matrix4f posquat2eigen4f(const nlohmann::json& j); + Eigen::Matrix4f posquat2eigen4f(const simox::json::json& j); std::vector<Eigen::Matrix4f> posquatArray2eigen4fVector(const std::string& str); std::vector<Eigen::Matrix4f> posquatArray2eigen4fVector(const char* str); - std::vector<Eigen::Matrix4f> posquatArray2eigen4fVector(const nlohmann::json& j); + std::vector<Eigen::Matrix4f> posquatArray2eigen4fVector(const simox::json::json& j); std::string eigen4f2posquatJson(const Eigen::Matrix4f& str); std::string eigen4fVector2posquatArrayJson(const std::vector<Eigen::Matrix4f>& str); std::map<std::string, float> json2NameValueMap(const std::string& str); std::map<std::string, float> json2NameValueMap(const char* str); - std::map<std::string, float> json2NameValueMap(const nlohmann::json& j); + std::map<std::string, float> json2NameValueMap(const simox::json::json& j); } diff --git a/SimoxUtility/json/eigen_conversion.cpp b/SimoxUtility/json/eigen_conversion.cpp index 23044671994debf89f1bb23197086b2e3f7f93fd..ed158b365c3a61fc5ea844c4e920e47c4f192303 100644 --- a/SimoxUtility/json/eigen_conversion.cpp +++ b/SimoxUtility/json/eigen_conversion.cpp @@ -8,7 +8,7 @@ namespace Eigen { template <> - void from_json<Eigen::Vector3f>(const nlohmann::json& j, Eigen::MatrixBase<Eigen::Vector3f>& vector) + void from_json<Eigen::Vector3f>(const ::simox::json::json& j, Eigen::MatrixBase<Eigen::Vector3f>& vector) { if (j.is_object()) { @@ -24,7 +24,7 @@ namespace Eigen template <> - void from_json<Eigen::Matrix4f>(const nlohmann::json& j, Eigen::MatrixBase<Eigen::Matrix4f>& matrix) + void from_json<Eigen::Matrix4f>(const ::simox::json::json& j, Eigen::MatrixBase<Eigen::Matrix4f>& matrix) { if (j.is_object()) { diff --git a/SimoxUtility/json/eigen_conversion.h b/SimoxUtility/json/eigen_conversion.h index 2dbb731c0c76643155e03678bb6f99d97e7aa506..d0a8162970fec5447a7406554c7068af20aa20d4 100644 --- a/SimoxUtility/json/eigen_conversion.h +++ b/SimoxUtility/json/eigen_conversion.h @@ -1,17 +1,18 @@ #pragma once -#include "json.hpp" - #include <Eigen/Core> +#include "json.h" + + /** - * Provide `to_json()` and `from_json()` overloads for `nlohmann::json`, + * Provide `to_json()` and `from_json()` overloads for `simox::json::json`, * which allows simple syntax like: * * @code * Eigen::Matrix3f in, out; * - * nlohmann::json j; + * simox::json::json j; * j = in; * out = j.get<Eigen::Matrix3f>(); * @endcode @@ -27,18 +28,18 @@ namespace Eigen /// Writes the matrix as list of rows. template <typename Derived> - void to_json(nlohmann::json& j, const Eigen::MatrixBase<Derived>& matrix); + void to_json(simox::json::json& j, const Eigen::MatrixBase<Derived>& matrix); /// Reads the matrix from list of rows. template <typename Derived> - void from_json(const nlohmann::json& j, Eigen::MatrixBase<Derived>& matrix); + void from_json(const simox::json::json& j, Eigen::MatrixBase<Derived>& matrix); // Specialization for Eigen::Vector3f (implemented in .cpp) /// If `j` is an object, reads vector from `x, y, z` keys. Otherwise, reads it as matrix. template <> - void from_json<Eigen::Vector3f>(const nlohmann::json& j, Eigen::MatrixBase<Eigen::Vector3f>& vector); + void from_json<Eigen::Vector3f>(const simox::json::json& j, Eigen::MatrixBase<Eigen::Vector3f>& vector); // Specialization for Eigen::Matrix4f as transformation matrix (implemented in .cpp). @@ -50,29 +51,29 @@ namespace Eigen * Otherweise, reads it from list of rows. */ template <> - void from_json<Eigen::Matrix4f>(const nlohmann::json& j, Eigen::MatrixBase<Eigen::Matrix4f>& matrix); + void from_json<Eigen::Matrix4f>(const simox::json::json& j, Eigen::MatrixBase<Eigen::Matrix4f>& matrix); // Eigen::Quaternion /// Writes the quaternion with `qw, qx, qy, qz` keys. template <typename Derived> - void to_json(nlohmann::json& j, const Eigen::QuaternionBase<Derived>& quat); + void to_json(simox::json::json& j, const Eigen::QuaternionBase<Derived>& quat); /// Reads the quaternion from `qw, qx, qy, qz` keys. template <typename Derived> - void from_json(const nlohmann::json& j, Eigen::QuaternionBase<Derived>& quat); + void from_json(const simox::json::json& j, Eigen::QuaternionBase<Derived>& quat); // Eigen::Transform (Isometry, Affine, ...) template <typename T, int N, int Type> - void to_json(nlohmann::json& j, const Eigen::Transform<T,N,Type>& transform) + void to_json(simox::json::json& j, const Eigen::Transform<T,N,Type>& transform) { to_json(j, transform.matrix()); } template <typename T, int N, int Type> - void from_json(const nlohmann::json& j, Eigen::Transform<T,N,Type>& transform) + void from_json(const simox::json::json& j, Eigen::Transform<T,N,Type>& transform) { from_json(j, transform.matrix()); } @@ -88,13 +89,13 @@ namespace jsonbase /// Writes the matrix as list of rows. template <typename Derived> - void to_json(nlohmann::json& j, const Eigen::MatrixBase<Derived>& matrix) + void to_json(simox::json::json& j, const Eigen::MatrixBase<Derived>& matrix) { for (int row = 0; row < matrix.rows(); ++row) { if (matrix.cols() > 1) { - nlohmann::json jrow = nlohmann::json::array(); + simox::json::json jrow = simox::json::json::array(); for (int col = 0; col < matrix.cols(); ++col) { jrow.push_back(matrix(row, col)); @@ -110,7 +111,7 @@ namespace jsonbase /// Reads the matrix from list of rows. template <typename Derived> - void from_json(const nlohmann::json& j, Eigen::MatrixBase<Derived>& matrix) + void from_json(const simox::json::json& j, Eigen::MatrixBase<Derived>& matrix) { using Scalar = typename Eigen::MatrixBase<Derived>::Scalar; using Index = typename Eigen::MatrixBase<Derived>::Index; @@ -136,20 +137,20 @@ namespace jsonbase template <typename Derived> - void to_json(nlohmann::json& j, const Eigen::MatrixBase<Derived>& matrix) + void to_json(simox::json::json& j, const Eigen::MatrixBase<Derived>& matrix) { jsonbase::to_json(j, matrix); } template <typename Derived> - void from_json(const nlohmann::json& j, Eigen::MatrixBase<Derived>& matrix) + void from_json(const simox::json::json& j, Eigen::MatrixBase<Derived>& matrix) { jsonbase::from_json(j, matrix); } template <typename Derived> - void to_json(nlohmann::json& j, const Eigen::QuaternionBase<Derived>& quat) + void to_json(simox::json::json& j, const Eigen::QuaternionBase<Derived>& quat) { j["qw"] = quat.w(); j["qx"] = quat.x(); @@ -158,7 +159,7 @@ namespace jsonbase } template <typename Derived> - void from_json(const nlohmann::json& j, Eigen::QuaternionBase<Derived>& quat) + void from_json(const simox::json::json& j, Eigen::QuaternionBase<Derived>& quat) { using Scalar = typename Eigen::QuaternionBase<Derived>::Scalar; quat.w() = j.at("qw").get<Scalar>(); diff --git a/SimoxUtility/json/error.cpp b/SimoxUtility/json/error.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dfe742ba13f907c7b19d1f500143415723608746 --- /dev/null +++ b/SimoxUtility/json/error.cpp @@ -0,0 +1,27 @@ +#include "error.h" + + +namespace simox::json::error +{ + + JsonError::JsonError(const std::string& message) : + simox::error::SimoxError(message) + { + } + + + IOError::IOError(const std::string& msg) : JsonError(msg) + { + } + + + ParseError::ParseError(const std::string& msg) : JsonError(msg) + { + } + + + ConversionError::ConversionError(const std::string& msg) : JsonError(msg) + { + } + +} diff --git a/SimoxUtility/json/error.h b/SimoxUtility/json/error.h new file mode 100644 index 0000000000000000000000000000000000000000..d2ecd81928f6a521cfc9e63df583852c6dc9a0cd --- /dev/null +++ b/SimoxUtility/json/error.h @@ -0,0 +1,45 @@ +#pragma once + +#include <SimoxUtility/error/SimoxError.h> + + +namespace simox::json::error +{ + + /** + * @brief An exception thrown by the `simox::json` namespace. + */ + struct JsonError : public simox::error::SimoxError + { + JsonError(const std::string& message); + }; + + + /** + * @brief Indicates that IO access to a file failed. + */ + struct IOError : public JsonError + { + IOError(const std::string& msg); + }; + + + /** + * @brief Indicates that a JSON file could not be parsed. + */ + struct ParseError : public JsonError + { + ParseError(const std::string& msg); + }; + + + /** + * @brief Indicates that a JSON document could not be converted to a + * business object. + */ + struct ConversionError : public JsonError + { + ConversionError(const std::string& msg); + }; + +} diff --git a/SimoxUtility/json/io.cpp b/SimoxUtility/json/io.cpp index 605ee3ded6445e6ee3301009bfdc17ed9d4ec222..a589381b08a310e64a1a73907e9661e168cd2403 100644 --- a/SimoxUtility/json/io.cpp +++ b/SimoxUtility/json/io.cpp @@ -1,27 +1,17 @@ #include "io.h" +#include "error.h" -#include <iostream> #include <filesystem> #include <fstream> +#include <iostream> namespace fs = std::filesystem; -namespace -{ - void checkExists(const std::string& filename, const std::string& prefix = "") - { - if (!fs::exists(filename)) - { - throw std::ios_base::failure(prefix + "File \"" + filename + "\" does not exist."); - } - } -} - -namespace nlohmann +namespace simox { - json read_json(const std::string& filename) + json::json json::read(const std::string& filename) { std::ifstream ifs; // Allow throwing std::ios_base::failure. @@ -30,28 +20,42 @@ namespace nlohmann try { ifs.open(filename); - return read_json(ifs); + return simox::json::read(ifs); } catch (const std::ios_base::failure& e) { // Add a more useful message. - const std::string msg = "Failed to read file \"" + filename + "\": "; - checkExists(filename, msg); - throw std::ios_base::failure(msg + std::string(e.what())); + std::string msg = "Failed to read file \"" + filename + "\": "; + if (not fs::exists(filename)) + { + msg += "File \"" + filename + "\" does not exist."; + } + else + { + msg += std::string(e.what()); + } + throw simox::json::error::IOError(msg); } } - json read_json(std::istream& is) + json::json json::read(std::istream& is) { json j; - is >> j; + try + { + is >> j; + } + catch (const json::parse_error& e) + { + throw error::ParseError(e.what()); + } return j; } - void write_json(const std::string& filename, const json& j, - const int indent, const char indent_char) + void json::write(const std::string& filename, const json& j, + const int indent, const char indent_char) { std::ofstream ofs; // Allow throwing std::ios_base::failure. @@ -60,18 +64,19 @@ namespace nlohmann try { ofs.open(filename); - write_json(ofs, j, indent, indent_char); + simox::json::write(ofs, j, indent, indent_char); } catch (const std::ios_base::failure& e) { // Add a more useful message. const std::string msg = "Failed to write file \"" + filename + "\": "; - throw std::ios_base::failure(msg + std::string(e.what())); + throw error::IOError(msg + std::string(e.what())); } } - void write_json(std::ostream& os, const json& j, const int indent, const char indent_char) + void json::write(std::ostream& os, const json& j, + const int indent, const char indent_char) { os << j.dump(indent, indent_char); } @@ -79,3 +84,30 @@ namespace nlohmann } + +nlohmann::json nlohmann::read_json(const std::string& filename) +{ + return simox::json::read(filename); +} + + +nlohmann::json nlohmann::read_json(std::istream& is) +{ + return simox::json::read(is); +} + + +void nlohmann::write_json(const std::string& filename, const json& j, + const int indent, const char indent_char) +{ + simox::json::write(filename, j, indent, indent_char); +} + + +void nlohmann::write_json(std::ostream& os, const json& j, + const int indent, const char indent_char) +{ + simox::json::write(os, j, indent, indent_char); +} + + diff --git a/SimoxUtility/json/io.h b/SimoxUtility/json/io.h index f651edbc909d30d25d0c6ae274b0a1a9c94f1ccc..a8f036c6bddae690b2b7441110068ce2f2b8bd75 100644 --- a/SimoxUtility/json/io.h +++ b/SimoxUtility/json/io.h @@ -1,9 +1,10 @@ #pragma once -#include "json.hpp" +#include "error.h" +#include "json.h" -namespace nlohmann +namespace simox::json { /** @@ -12,16 +13,47 @@ namespace nlohmann * @param filename The name of the file to read from. * @return The JSON document. * - * @throw std::ios_base::failure If IO access fails. + * @throw `simox::json::error::IOError` If IO access fails. + * @throw `simox::json::error::ParseError` If parsing fails. */ - json read_json(const std::string& filename); + json read(const std::string& filename); /** * @brief Read a JSON document from the given in-stream. + * * @param is The in-stream. * @return The JSON document. + * + * @throw `simox::json::error::ParseError` If parsing fails. */ - json read_json(std::istream& is); + json read(std::istream& is); + + + /** + * @brief Read a JSON document from the given file + * and convert it to the business-object type `BO`. + * + * @param filename The name of the file to read from. + * @return The business object. + * + * @throw `simox::json::error::IOError` If IO access fails. + * @throw `simox::json::error::ParseError` If parsing fails. + * @throw `simox::json::error::ConversionError` + * If converting the JSON document to the BO fails. + */ + template <class BO> + BO read(const std::string& filename) + { + const json j = simox::json::read(filename); + try + { + return j.get<BO>(); + } + catch (const json::out_of_range& e) // Add other exception types if they come up. + { + throw error::ConversionError(e.what()); + } + } /** @@ -32,19 +64,64 @@ namespace nlohmann * @param indent See nlohmann::json::dump(). * @param indent_char See nlohmann::json::dump(). * - * @throw std::ios_base::failure If IO access fails. + * @throw `simox::json::error::IOError` If IO access fails. */ - void write_json(const std::string& filename, const json& j, - const int indent = -1, const char indent_char = ' '); + void write(const std::string& filename, const json& j, + const int indent = -1, const char indent_char = ' '); /** * @brief Write a JSON document to the given out-stream. + * * @param os The out-stream. * @param j The JSON document. - * @param indent See nlohmann::json::dump(). - * @param indent_char See nlohmann::json::dump(). + * @param indent The number of indents, if nonnegative (see nlohmann::json::dump()). + * @param indent_char The character used for indents (see nlohmann::json::dump()). */ + void write(std::ostream& os, const json& j, + const int indent = -1, const char indent_char = ' '); + + + /** + * @brief Write a business object as JSON to the given file. + * + * @param filename The name of the file to write to. + * @param bo The business object. + * @param indent The number of indents, if nonnegative (see nlohmann::json::dump()). + * @param indent_char The character used for indents (see nlohmann::json::dump()). + * + * @throw `simox::json::error::IOError` If IO access fails. + * @throw `simox::json::error::ConversionError` If the bo could not access fails. + */ + template <class BO> + void write(const std::string& filename, const BO& bo, + const int indent = -1, const char indent_char = ' ') + { + json j; + try + { + j = bo; + } + catch (const json::out_of_range& e) // Add other exception types if they come up. + { + throw error::ConversionError(e.what()); + } + simox::json::write(filename, j, indent, indent_char); + } + +} + + +// Legacy names. +namespace nlohmann +{ + + json read_json(const std::string& filename); + json read_json(std::istream& is); + + void write_json(const std::string& filename, const json& j, + const int indent = -1, const char indent_char = ' '); void write_json(std::ostream& os, const json& j, const int indent = -1, const char indent_char = ' '); } + diff --git a/SimoxUtility/json/json.h b/SimoxUtility/json/json.h new file mode 100644 index 0000000000000000000000000000000000000000..2e44c76672f457d116a7f3b1f3c8052f1665b3c7 --- /dev/null +++ b/SimoxUtility/json/json.h @@ -0,0 +1,10 @@ +#pragma once + +#include "json.hpp" + + +namespace simox::json +{ + /// A JSON document. + using json = nlohmann::json; +} diff --git a/SimoxUtility/json/util.cpp b/SimoxUtility/json/util.cpp index 0f6112b4283aa906811eddcb7ec436683d56614e..c539408b4058304ffade89efe973488ff0414834 100644 --- a/SimoxUtility/json/util.cpp +++ b/SimoxUtility/json/util.cpp @@ -5,7 +5,8 @@ namespace simox { - nlohmann::json::const_reference json::at_any_key(const nlohmann::json& j, const std::vector<std::string>& keys) + json::json::const_reference + json::at_any_key(const json& j, const std::vector<std::string>& keys) { for (const std::string& key : keys) { diff --git a/SimoxUtility/json/util.h b/SimoxUtility/json/util.h index cfab6890d73b157affb29e18a26fe584d1f4684c..afb45554d9f0ca9f5993108b4f50c7cc74b5300d 100644 --- a/SimoxUtility/json/util.h +++ b/SimoxUtility/json/util.h @@ -2,7 +2,7 @@ #include <optional> -#include "json.hpp" +#include "json.h" namespace simox::json @@ -10,16 +10,18 @@ namespace simox::json /** * @brief Get the value at the first key in `keys` contained in `j`. + * * @param j The JSON object. * @param keys The keys. * @return The value at the first contained key. * * @throw std::out_of_range If none of the keys is found in `j`. */ - nlohmann::json::const_reference at_any_key(const nlohmann::json& j, const std::vector<std::string>& keys); + json::const_reference at_any_key(const json& j, const std::vector<std::string>& keys); + template <class T> - T get_at_any_key(const nlohmann::json& j, const std::vector<std::string>& keys) + T get_at_any_key(const json& j, const std::vector<std::string>& keys) { return at_any_key(j, keys).get<T>(); } diff --git a/SimoxUtility/tests/json/IOTest.cpp b/SimoxUtility/tests/json/IOTest.cpp index 171bbf19ac32cc899be4654fda69a6ba5df92112..a2456b6482537ebef65d5ac4ec521c423192fa4c 100644 --- a/SimoxUtility/tests/json/IOTest.cpp +++ b/SimoxUtility/tests/json/IOTest.cpp @@ -11,6 +11,7 @@ #include <filesystem> #include <SimoxUtility/json/io.h> +#include <SimoxUtility/json/error.h> namespace fs = std::filesystem; @@ -19,7 +20,7 @@ struct Fixture { const std::string FILENAME = "JsonIOTest.json"; - nlohmann::json testj; + simox::json::json testj; Fixture() @@ -56,7 +57,7 @@ BOOST_AUTO_TEST_CASE(test_read_json_existent) BOOST_CHECK(fs::exists(FILENAME)); // Test reading. - const nlohmann::json j = nlohmann::read_json(FILENAME); + const simox::json::json j = simox::json::read(FILENAME); BOOST_CHECK_EQUAL(j, testj); BOOST_CHECK_EQUAL(j.at("s").get<std::string>(), testj.at("s").get<std::string>()); @@ -70,8 +71,8 @@ BOOST_AUTO_TEST_CASE(test_read_json_nonexistent) BOOST_CHECK(!fs::exists(FILENAME)); // Test reading. - nlohmann::json j; - BOOST_CHECK_THROW(j = nlohmann::read_json(FILENAME), std::ios_base::failure); + simox::json::json j; + BOOST_CHECK_THROW(j = simox::json::read(FILENAME), simox::json::error::IOError); } @@ -81,7 +82,7 @@ BOOST_AUTO_TEST_CASE(test_write_json_valid) BOOST_CHECK(!fs::exists(FILENAME)); // Test writing. - nlohmann::write_json(FILENAME, testj); + simox::json::write(FILENAME, testj); // Check that something has been written. BOOST_CHECK(fs::exists(FILENAME)); } @@ -96,7 +97,7 @@ BOOST_AUTO_TEST_CASE(test_write_json_invalid) BOOST_CHECK(fs::exists(FILENAME)); // Test writing. - BOOST_CHECK_THROW(nlohmann::write_json(FILENAME, testj);, std::ios_base::failure); + BOOST_CHECK_THROW(simox::json::write(FILENAME, testj), simox::json::error::IOError); // Clean up. fs::remove(FILENAME); @@ -107,14 +108,14 @@ BOOST_AUTO_TEST_CASE(test_write_json_invalid) BOOST_AUTO_TEST_CASE(test_read_after_write_json) { // Ensure file does not exist. - BOOST_CHECK(!fs::exists(FILENAME)); + BOOST_CHECK(not fs::exists(FILENAME)); // Test writing. - nlohmann::write_json(FILENAME, testj); + simox::json::write(FILENAME, testj); // Test reading. - nlohmann::json j; - BOOST_CHECK_NO_THROW(j = nlohmann::read_json(FILENAME)); + simox::json::json j; + BOOST_CHECK_NO_THROW(j = simox::json::read(FILENAME)); BOOST_CHECK_EQUAL(j, testj); BOOST_CHECK_EQUAL(j.at("s").get<std::string>(), testj.at("s").get<std::string>());