diff --git a/include/nlohmann/detail/macro_scope.hpp b/include/nlohmann/detail/macro_scope.hpp index 77acf04c76..0fbf881b07 100644 --- a/include/nlohmann/detail/macro_scope.hpp +++ b/include/nlohmann/detail/macro_scope.hpp @@ -275,22 +275,58 @@ #define NLOHMANN_JSON_FROM(v1) nlohmann_json_j.at(#v1).get_to(nlohmann_json_t.v1); /*! -@brief macro +@brief macro to briefly define intrusive serialization of a given type to/from JSON +@note you can define your own specialized macroses like NLOHMANN_DEFINE_TYPE_INTRUSIVE +@def NLOHMANN_DEFINE_TYPE_INTRUSIVE_IMPL +@since version 3.9.2 +*/ +#define NLOHMANN_DEFINE_TYPE_INTRUSIVE_IMPL(BasicJsonType, Type, ...) \ + friend void to_json(BasicJsonType& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ + friend void from_json(const BasicJsonType& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) } + +/*! +@brief macro to briefly define non-intrusive serialization of a given type to/from JSON +@note you can define your own specialized macroses like NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE +@def NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_IMPL +@since version 3.9.2 +*/ +#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_IMPL(BasicJsonType, Type, ...) \ + inline void to_json(BasicJsonType& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ + inline void from_json(const BasicJsonType& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) } + +/*! +@brief macro to briefly define intrusive serialization of given type to/from nlohmann::json @def NLOHMANN_DEFINE_TYPE_INTRUSIVE @since version 3.9.0 +@sa NLOHMANN_DEFINE_TYPE_INTRUSIVE_IMPL */ -#define NLOHMANN_DEFINE_TYPE_INTRUSIVE(Type, ...) \ - friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ - friend void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) } +#define NLOHMANN_DEFINE_TYPE_INTRUSIVE(Type, ...) NLOHMANN_DEFINE_TYPE_INTRUSIVE_IMPL(nlohmann::json, Type, __VA_ARGS__) /*! -@brief macro +@brief macro to briefly define non-intrusive serialization of given type to/from nlohmann::json @def NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE @since version 3.9.0 +@sa NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_IMPL +*/ +#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Type, ...) NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_IMPL(nlohmann::json, Type, __VA_ARGS__) + +/*! +@brief macro to briefly define intrusive serialization of a given type to/from any basic_json object +@def NLOHMANN_DEFINE_TYPE_INTRUSIVE_T +@since version 3.9.2 +*/ +#define NLOHMANN_DEFINE_TYPE_INTRUSIVE_T(Type, ...) \ + template friend void to_json(BasicJsonType& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ + template friend void from_json(const BasicJsonType& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) } + +/*! +@brief macro to briefly define non-intrusive serialization of a given type to/from any basic_json object +@def NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_T +@since version 3.9.2 */ -#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Type, ...) \ - inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ - inline void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) } +#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_T(Type, ...) \ + template void to_json(BasicJsonType& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ + template void from_json(const BasicJsonType& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) } #ifndef JSON_USE_IMPLICIT_CONVERSIONS #define JSON_USE_IMPLICIT_CONVERSIONS 1 diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 8b6344f921..fc7d5a51e2 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -2352,22 +2352,58 @@ JSON_HEDLEY_DIAGNOSTIC_POP #define NLOHMANN_JSON_FROM(v1) nlohmann_json_j.at(#v1).get_to(nlohmann_json_t.v1); /*! -@brief macro +@brief macro to briefly define intrusive serialization of a given type to/from JSON +@note you can define your own specialized macroses like NLOHMANN_DEFINE_TYPE_INTRUSIVE +@def NLOHMANN_DEFINE_TYPE_INTRUSIVE_IMPL +@since version 3.9.2 +*/ +#define NLOHMANN_DEFINE_TYPE_INTRUSIVE_IMPL(BasicJsonType, Type, ...) \ + friend void to_json(BasicJsonType& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ + friend void from_json(const BasicJsonType& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) } + +/*! +@brief macro to briefly define non-intrusive serialization of a given type to/from JSON +@note you can define your own specialized macroses like NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE +@def NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_IMPL +@since version 3.9.2 +*/ +#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_IMPL(BasicJsonType, Type, ...) \ + inline void to_json(BasicJsonType& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ + inline void from_json(const BasicJsonType& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) } + +/*! +@brief macro to briefly define intrusive serialization of given type to/from nlohmann::json @def NLOHMANN_DEFINE_TYPE_INTRUSIVE @since version 3.9.0 +@sa NLOHMANN_DEFINE_TYPE_INTRUSIVE_IMPL */ -#define NLOHMANN_DEFINE_TYPE_INTRUSIVE(Type, ...) \ - friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ - friend void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) } +#define NLOHMANN_DEFINE_TYPE_INTRUSIVE(Type, ...) NLOHMANN_DEFINE_TYPE_INTRUSIVE_IMPL(nlohmann::json, Type, __VA_ARGS__) /*! -@brief macro +@brief macro to briefly define non-intrusive serialization of given type to/from nlohmann::json @def NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE @since version 3.9.0 +@sa NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_IMPL +*/ +#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Type, ...) NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_IMPL(nlohmann::json, Type, __VA_ARGS__) + +/*! +@brief macro to briefly define intrusive serialization of a given type to/from any basic_json object +@def NLOHMANN_DEFINE_TYPE_INTRUSIVE_T +@since version 3.9.2 +*/ +#define NLOHMANN_DEFINE_TYPE_INTRUSIVE_T(Type, ...) \ + template friend void to_json(BasicJsonType& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ + template friend void from_json(const BasicJsonType& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) } + +/*! +@brief macro to briefly define non-intrusive serialization of a given type to/from any basic_json object +@def NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_T +@since version 3.9.2 */ -#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Type, ...) \ - inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ - inline void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) } +#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_T(Type, ...) \ + template void to_json(BasicJsonType& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ + template void from_json(const BasicJsonType& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) } #ifndef JSON_USE_IMPLICIT_CONVERSIONS #define JSON_USE_IMPLICIT_CONVERSIONS 1 diff --git a/test/src/unit-udt_macro.cpp b/test/src/unit-udt_macro.cpp index a13ac006b3..073f32e294 100644 --- a/test/src/unit-udt_macro.cpp +++ b/test/src/unit-udt_macro.cpp @@ -36,214 +36,170 @@ using nlohmann::json; namespace persons { -class person_with_private_data -{ - private: - std::string name = ""; - int age = 0; - json metadata = nullptr; - - public: - bool operator==(const person_with_private_data& rhs) const - { - return name == rhs.name && age == rhs.age && metadata == rhs.metadata; - } +#define CREATE_PERSON(ClassName, Visibility) \ + class ClassName { \ + Visibility: \ + std::string name = ""; \ + int age = 0; \ + json metadata = nullptr; \ + public: \ + bool operator==(const ClassName& rhs) const \ + { \ + return name == rhs.name && age == rhs.age && metadata == rhs.metadata; \ + } \ + ClassName() = default; \ + ClassName(std::string name_, int age_, json metadata_) \ + : name(std::move(name_)) \ + , age(age_) \ + , metadata(std::move(metadata_)) \ + {} + +#define CREATE_PERSON_WITH_ALPHABET(ClassName, Visibility) \ + class ClassName{ \ + public: \ + bool operator==(const ClassName& other) const \ + { \ + return a == other.a && \ + b == other.b && \ + c == other.c && \ + d == other.d && \ + e == other.e && \ + f == other.f && \ + g == other.g && \ + h == other.h && \ + i == other.i && \ + j == other.j && \ + k == other.k && \ + l == other.l && \ + m == other.m && \ + n == other.n && \ + o == other.o && \ + p == other.p && \ + q == other.q && \ + r == other.r && \ + s == other.s && \ + t == other.t && \ + u == other.u && \ + v == other.v && \ + w == other.w && \ + x == other.x && \ + y == other.y && \ + z == other.z; \ + } \ + Visibility: \ + int a = 0; \ + int b = 0; \ + int c = 0; \ + int d = 0; \ + int e = 0; \ + int f = 0; \ + int g = 0; \ + int h = 0; \ + int i = 0; \ + int j = 0; \ + int k = 0; \ + int l = 0; \ + int m = 0; \ + int n = 0; \ + int o = 0; \ + int p = 0; \ + int q = 0; \ + int r = 0; \ + int s = 0; \ + int t = 0; \ + int u = 0; \ + int v = 0; \ + int w = 0; \ + int x = 0; \ + int y = 0; \ + int z = 0; + +CREATE_PERSON(person_with_private_data, private) +NLOHMANN_DEFINE_TYPE_INTRUSIVE(person_with_private_data, age, name, metadata) +}; - person_with_private_data() = default; - person_with_private_data(std::string name_, int age_, json metadata_) - : name(std::move(name_)) - , age(age_) - , metadata(std::move(metadata_)) - {} +CREATE_PERSON(person_without_private_data_1, public) +NLOHMANN_DEFINE_TYPE_INTRUSIVE(person_without_private_data_1, age, name, metadata) +}; - NLOHMANN_DEFINE_TYPE_INTRUSIVE(person_with_private_data, age, name, metadata) +CREATE_PERSON(person_without_private_data_2, public) }; +NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(person_without_private_data_2, age, name, metadata) -class person_without_private_data_1 -{ - public: - std::string name = ""; - int age = 0; - json metadata = nullptr; - bool operator==(const person_without_private_data_1& rhs) const - { - return name == rhs.name && age == rhs.age && metadata == rhs.metadata; - } +CREATE_PERSON(person_t_with_private_data, private) +NLOHMANN_DEFINE_TYPE_INTRUSIVE_T(person_t_with_private_data, age, name, metadata) +}; - person_without_private_data_1() = default; - person_without_private_data_1(std::string name_, int age_, json metadata_) - : name(std::move(name_)) - , age(age_) - , metadata(std::move(metadata_)) - {} +CREATE_PERSON(person_t_without_private_data_1, public) +NLOHMANN_DEFINE_TYPE_INTRUSIVE_T(person_t_without_private_data_1, age, name, metadata) +}; - NLOHMANN_DEFINE_TYPE_INTRUSIVE(person_without_private_data_1, age, name, metadata) +CREATE_PERSON(person_t_without_private_data_2, public) }; +NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_T(person_t_without_private_data_2, age, name, metadata) -class person_without_private_data_2 -{ - public: - std::string name = ""; - int age = 0; - json metadata = nullptr; - bool operator==(const person_without_private_data_2& rhs) const - { - return name == rhs.name && age == rhs.age && metadata == rhs.metadata; - } +CREATE_PERSON_WITH_ALPHABET(person_with_private_alphabet, private) +NLOHMANN_DEFINE_TYPE_INTRUSIVE(person_with_private_alphabet, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z) +}; - person_without_private_data_2() = default; - person_without_private_data_2(std::string name_, int age_, json metadata_) - : name(std::move(name_)) - , age(age_) - , metadata(std::move(metadata_)) - {} +CREATE_PERSON_WITH_ALPHABET(person_with_public_alphabet, public) }; +NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(person_with_public_alphabet, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z) -NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(person_without_private_data_2, age, name, metadata) -class person_with_private_alphabet -{ - public: - bool operator==(const person_with_private_alphabet& other) const - { - return a == other.a && - b == other.b && - c == other.c && - d == other.d && - e == other.e && - f == other.f && - g == other.g && - h == other.h && - i == other.i && - j == other.j && - k == other.k && - l == other.l && - m == other.m && - n == other.n && - o == other.o && - p == other.p && - q == other.q && - r == other.r && - s == other.s && - t == other.t && - u == other.u && - v == other.v && - w == other.w && - x == other.x && - y == other.y && - z == other.z; - } - - private: - int a = 0; - int b = 0; - int c = 0; - int d = 0; - int e = 0; - int f = 0; - int g = 0; - int h = 0; - int i = 0; - int j = 0; - int k = 0; - int l = 0; - int m = 0; - int n = 0; - int o = 0; - int p = 0; - int q = 0; - int r = 0; - int s = 0; - int t = 0; - int u = 0; - int v = 0; - int w = 0; - int x = 0; - int y = 0; - int z = 0; - NLOHMANN_DEFINE_TYPE_INTRUSIVE(person_with_private_alphabet, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z) +CREATE_PERSON_WITH_ALPHABET(person_t_with_private_alphabet, private) +NLOHMANN_DEFINE_TYPE_INTRUSIVE_T(person_t_with_private_alphabet, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z) }; -class person_with_public_alphabet -{ - public: - bool operator==(const person_with_public_alphabet& other) const - { - return a == other.a && - b == other.b && - c == other.c && - d == other.d && - e == other.e && - f == other.f && - g == other.g && - h == other.h && - i == other.i && - j == other.j && - k == other.k && - l == other.l && - m == other.m && - n == other.n && - o == other.o && - p == other.p && - q == other.q && - r == other.r && - s == other.s && - t == other.t && - u == other.u && - v == other.v && - w == other.w && - x == other.x && - y == other.y && - z == other.z; - } - - int a = 0; - int b = 0; - int c = 0; - int d = 0; - int e = 0; - int f = 0; - int g = 0; - int h = 0; - int i = 0; - int j = 0; - int k = 0; - int l = 0; - int m = 0; - int n = 0; - int o = 0; - int p = 0; - int q = 0; - int r = 0; - int s = 0; - int t = 0; - int u = 0; - int v = 0; - int w = 0; - int x = 0; - int y = 0; - int z = 0; +CREATE_PERSON_WITH_ALPHABET(person_t_with_public_alphabet, public) }; +NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_T(person_t_with_public_alphabet, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z) -NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(person_with_public_alphabet, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z) } // namespace persons -TEST_CASE_TEMPLATE("Serialization/deserialization via NLOHMANN_DEFINE_TYPE_INTRUSIVE", T, - persons::person_with_private_data, - persons::person_without_private_data_1, - persons::person_without_private_data_2) +// Trick described in https://github.com/onqtam/doctest/blob/master/doc/markdown/parameterized-tests.md +// in note "if you need parameterization on more than 1 type" +template +struct TestTypePair +{ + using TestedType = TestedType_; + using BasicJsonType = BasicJsonType_; +}; + +#define PERSON_PAIRS \ + TestTypePair, \ + TestTypePair, \ + TestTypePair, \ + TestTypePair, \ + TestTypePair, \ + TestTypePair, \ + TestTypePair, \ + TestTypePair, \ + TestTypePair + +TEST_CASE_TEMPLATE("Serialization/deserialization via NLOHMANN_DEFINE_TYPE_INTRUSIVE T", PairT, PERSON_PAIRS) { + using T = typename PairT::TestedType; + using json = typename PairT::BasicJsonType; + SECTION("person") { // serialization T p1("Erik", 1, {{"haircuts", 2}}); - CHECK(json(p1).dump() == "{\"age\":1,\"metadata\":{\"haircuts\":2},\"name\":\"Erik\"}"); + if ( std::is_same::value ) + { + CHECK(json(p1).dump() == "{\"age\":1,\"name\":\"Erik\",\"metadata\":{\"haircuts\":2}}"); + } + else + { + CHECK(json(p1).dump() == "{\"age\":1,\"metadata\":{\"haircuts\":2},\"name\":\"Erik\"}"); + } // deserialization - auto p2 = json(p1).get(); + auto p2 = json(p1).template get(); CHECK(p2 == p1); // roundtrip @@ -253,19 +209,28 @@ TEST_CASE_TEMPLATE("Serialization/deserialization via NLOHMANN_DEFINE_TYPE_INTRU // check exception in case of missing field json j = json(p1); j.erase("age"); - CHECK_THROWS_WITH_AS(j.get(), "[json.exception.out_of_range.403] key 'age' not found", json::out_of_range); + CHECK_THROWS_WITH_AS(j.template get(), "[json.exception.out_of_range.403] key 'age' not found", typename json::out_of_range); } } -TEST_CASE_TEMPLATE("Serialization/deserialization of classes with 26 public/private member variables via NLOHMANN_DEFINE_TYPE_INTRUSIVE and NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE", T, - persons::person_with_private_alphabet, - persons::person_with_public_alphabet) +#define ALPHABET_PAIRS \ + TestTypePair, \ + TestTypePair, \ + TestTypePair, \ + TestTypePair, \ + TestTypePair, \ + TestTypePair + +TEST_CASE_TEMPLATE("Serialization/deserialization of classes with 26 public/private member variables via NLOHMANN_DEFINE_TYPE_INTRUSIVE and NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE", PairT, ALPHABET_PAIRS) { + using T = typename PairT::TestedType; + using json = typename PairT::BasicJsonType; + SECTION("alphabet") { { T obj1; - nlohmann::json j = obj1; //via json object + json j = obj1; //via json object T obj2; j.get_to(obj2); bool ok = (obj1 == obj2); @@ -274,9 +239,9 @@ TEST_CASE_TEMPLATE("Serialization/deserialization of classes with 26 public/priv { T obj1; - nlohmann::json j1 = obj1; //via json string + json j1 = obj1; //via json string std::string s = j1.dump(); - nlohmann::json j2 = nlohmann::json::parse(s); + json j2 = json::parse(s); T obj2; j2.get_to(obj2); bool ok = (obj1 == obj2); @@ -285,9 +250,9 @@ TEST_CASE_TEMPLATE("Serialization/deserialization of classes with 26 public/priv { T obj1; - nlohmann::json j1 = obj1; //via msgpack - std::vector buf = nlohmann::json::to_msgpack(j1); - nlohmann::json j2 = nlohmann::json::from_msgpack(buf); + json j1 = obj1; //via msgpack + std::vector buf = json::to_msgpack(j1); + json j2 = json::from_msgpack(buf); T obj2; j2.get_to(obj2); bool ok = (obj1 == obj2); @@ -296,9 +261,9 @@ TEST_CASE_TEMPLATE("Serialization/deserialization of classes with 26 public/priv { T obj1; - nlohmann::json j1 = obj1; //via bson - std::vector buf = nlohmann::json::to_bson(j1); - nlohmann::json j2 = nlohmann::json::from_bson(buf); + json j1 = obj1; //via bson + std::vector buf = json::to_bson(j1); + json j2 = json::from_bson(buf); T obj2; j2.get_to(obj2); bool ok = (obj1 == obj2); @@ -307,9 +272,9 @@ TEST_CASE_TEMPLATE("Serialization/deserialization of classes with 26 public/priv { T obj1; - nlohmann::json j1 = obj1; //via cbor - std::vector buf = nlohmann::json::to_cbor(j1); - nlohmann::json j2 = nlohmann::json::from_cbor(buf); + json j1 = obj1; //via cbor + std::vector buf = json::to_cbor(j1); + json j2 = json::from_cbor(buf); T obj2; j2.get_to(obj2); bool ok = (obj1 == obj2); @@ -318,9 +283,9 @@ TEST_CASE_TEMPLATE("Serialization/deserialization of classes with 26 public/priv { T obj1; - nlohmann::json j1 = obj1; //via ubjson - std::vector buf = nlohmann::json::to_ubjson(j1); - nlohmann::json j2 = nlohmann::json::from_ubjson(buf); + json j1 = obj1; //via ubjson + std::vector buf = json::to_ubjson(j1); + json j2 = json::from_ubjson(buf); T obj2; j2.get_to(obj2); bool ok = (obj1 == obj2);