File tree Expand file tree Collapse file tree 3 files changed +9
-2
lines changed Expand file tree Collapse file tree 3 files changed +9
-2
lines changed Original file line number Diff line number Diff line change 395
395
396
396
#define NLOHMANN_JSON_TO (v1 ) nlohmann_json_j[#v1] = nlohmann_json_t .v1;
397
397
#define NLOHMANN_JSON_FROM (v1 ) nlohmann_json_j.at(#v1).get_to(nlohmann_json_t .v1);
398
- #define NLOHMANN_JSON_FROM_WITH_DEFAULT (v1 ) nlohmann_json_t .v1 = nlohmann_json_j.value(#v1, nlohmann_json_default_obj.v1);
398
+ #define NLOHMANN_JSON_FROM_WITH_DEFAULT (v1 ) nlohmann_json_t .v1 = ! nlohmann_json_j.is_null() ? nlohmann_json_j. value(#v1, nlohmann_json_default_obj.v1) : nlohmann_json_default_obj.v1 ;
399
399
400
400
/* !
401
401
@brief macro
Original file line number Diff line number Diff line change @@ -2761,7 +2761,7 @@ JSON_HEDLEY_DIAGNOSTIC_POP
2761
2761
2762
2762
#define NLOHMANN_JSON_TO(v1) nlohmann_json_j[#v1] = nlohmann_json_t.v1;
2763
2763
#define NLOHMANN_JSON_FROM(v1) nlohmann_json_j.at(#v1).get_to(nlohmann_json_t.v1);
2764
- #define NLOHMANN_JSON_FROM_WITH_DEFAULT(v1) nlohmann_json_t.v1 = nlohmann_json_j.value(#v1, nlohmann_json_default_obj.v1);
2764
+ #define NLOHMANN_JSON_FROM_WITH_DEFAULT(v1) nlohmann_json_t.v1 = ! nlohmann_json_j.is_null() ? nlohmann_json_j. value(#v1, nlohmann_json_default_obj.v1) : nlohmann_json_default_obj.v1 ;
2765
2765
2766
2766
/*!
2767
2767
@brief macro
Original file line number Diff line number Diff line change @@ -551,6 +551,13 @@ TEST_CASE_TEMPLATE("Serialization/deserialization via NLOHMANN_DEFINE_TYPE_INTRU
551
551
CHECK (p3.getName () == " " );
552
552
CHECK (p3.getAge () == 0 );
553
553
CHECK (p3.getMetadata () == nullptr );
554
+
555
+ // check default value in case of empty json
556
+ const json j4;
557
+ T p4 = j4.get <T>();
558
+ CHECK (p4.getName () == " " );
559
+ CHECK (p4.getAge () == 0 );
560
+ CHECK (p4.getMetadata () == nullptr );
554
561
}
555
562
}
556
563
You can’t perform that action at this time.
0 commit comments