Skip to content

Commit 86e916e

Browse files
committed
Revert "Revert "Fix empty maps roundtrip and move to native tipi deps""
This reverts commit f95a02b.
1 parent 1ecca57 commit 86e916e

File tree

5 files changed

+29
-3
lines changed

5 files changed

+29
-3
lines changed

.tipi/deps

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
{
2-
"nlohmann/json" : { "@" : "v3.11.1", "x" : ["benchmarks"] }
3-
, "platform" : [ "Boost::+boost" ]
1+
{
2+
"nlohmann/json" : { "@" : "v3.11.2", "x" : ["benchmarks"] }
3+
, "tipi-deps/boost" : {
4+
"@" : "v1.80.0-without-submodules"
5+
, "u" : true
6+
, "packages" : ["boost_fusion"]
7+
, "targets" : ["Boost::fusion"]
8+
}
49
}

.tipi/id

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"host_name":"github.com","org_name":"cpp-pre","repo_name":"json"}

.tipi/opts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
set(BOOST_INCLUDE_LIBRARIES fusion)

pre/json/detail/jsonizer.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ namespace pre { namespace json { namespace detail {
111111
template<class T,
112112
enable_if_is_associative_container_t<T>* = nullptr>
113113
void operator()(const T& value) const {
114+
_json_object = nlohmann::json::object();
114115
for (const auto& each : value) {
115116
nlohmann::json json_subobject;
116117
jsonizer subjsonizer(json_subobject);

test/dejsonize_test.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,24 @@ BOOST_AUTO_TEST_CASE(maps) {
400400
BOOST_REQUIRE(some_deserialized == some);
401401
}
402402

403+
BOOST_AUTO_TEST_CASE(empty_map) {
404+
405+
std::map<std::string, std::string> some{};
406+
407+
auto some_json = pre::json::to_json(some);
408+
std::cout << some_json.dump(2) << std::endl;
409+
410+
auto some_deserialized = pre::json::from_json<decltype(some)>(some_json);
411+
412+
BOOST_REQUIRE(some_deserialized == some);
413+
414+
auto empty_map = pre::json::to_json( std::map<std::string, std::string> {} ).dump();
415+
BOOST_REQUIRE(empty_map != "null");
416+
BOOST_REQUIRE(empty_map == "{}");
417+
}
418+
419+
420+
403421

404422
namespace datamodel {
405423

0 commit comments

Comments
 (0)