@@ -1079,6 +1079,26 @@ TEST_CASE("value conversion")
10791079 j5.get <std::unordered_set<std::string>>();
10801080 }
10811081
1082+ SECTION (" std::map (array of pairs)" )
1083+ {
1084+ std::map<int , int > m{{0 , 1 }, {1 , 2 }, {2 , 3 }};
1085+ json j6 = m;
1086+
1087+ auto m2 = j6.get <std::map<int , int >>();
1088+ CHECK (m == m2);
1089+
1090+ json j7 = {0 , 1 , 2 , 3 };
1091+ CHECK_THROWS_AS ((j7.get <std::map<int , int >>()), json::type_error&);
1092+ CHECK_THROWS_WITH ((j7.get <std::map<int , int >>()), " [json.exception.type_error.302] type must be array, but is number" );
1093+
1094+ SECTION (" superfluous entries" )
1095+ {
1096+ json j8 = {{0 , 1 , 2 }, {1 , 2 , 3 }, {2 , 3 , 4 }};
1097+ m2 = j8.get <std::map<int , int >>();
1098+ CHECK (m == m2);
1099+ }
1100+ }
1101+
10821102 SECTION (" exception in case of a non-object type" )
10831103 {
10841104 CHECK_THROWS_AS ((json ().get <std::list<int >>()), json::type_error&);
@@ -1094,6 +1114,7 @@ TEST_CASE("value conversion")
10941114 CHECK_THROWS_WITH ((json ().get <std::vector<json>>()), " [json.exception.type_error.302] type must be array, but is null" );
10951115 CHECK_THROWS_WITH ((json ().get <std::list<json>>()), " [json.exception.type_error.302] type must be array, but is null" );
10961116 CHECK_THROWS_WITH ((json ().get <std::valarray<int >>()), " [json.exception.type_error.302] type must be array, but is null" );
1117+ CHECK_THROWS_WITH ((json ().get <std::map<int , int >>()), " [json.exception.type_error.302] type must be array, but is null" );
10971118 }
10981119 }
10991120 }
0 commit comments