@@ -116,6 +116,62 @@ TEST_CASE("CXX-1246: Canonical Extended JSON") {
116116 R"( { "number" : { "$numberInt" : "42" }, "bin" : { "$binary" : { "base64" : "ZGVhZGJlZWY=", "subType" : "04" } } })" );
117117}
118118
119+ TEST_CASE (" CXX-1712: Overloaded to_json Legacy (Implicit)" ) {
120+ using namespace bsoncxx ;
121+ using namespace builder ::basic;
122+
123+ types::b_binary bin_val{
124+ binary_sub_type::k_uuid, 8 , reinterpret_cast <const uint8_t *>(" deadbeef" )};
125+ auto arr = make_array (make_document (kvp (" foo" , 42 ), kvp (" bar" , " A" ), kvp (" baz" , bin_val)));
126+ auto output = bsoncxx::to_json (arr.view ());
127+
128+ REQUIRE (
129+ output ==
130+ R"( [ { "foo" : 42, "bar" : "A", "baz" : { "$binary" : "ZGVhZGJlZWY=", "$type" : "04" } } ])" );
131+ }
132+
133+ TEST_CASE (" CXX-1712: Overloaded to_json Legacy (Explicit)" ) {
134+ using namespace bsoncxx ;
135+ using namespace builder ::basic;
136+
137+ types::b_binary bin_val{
138+ binary_sub_type::k_uuid, 8 , reinterpret_cast <const uint8_t *>(" deadbeef" )};
139+ auto arr = make_array (make_document (kvp (" foo" , 42 ), kvp (" bar" , " A" ), kvp (" baz" , bin_val)));
140+ auto output = to_json (arr.view (), ExtendedJsonMode::k_legacy);
141+
142+ REQUIRE (
143+ output ==
144+ R"( [ { "foo" : 42, "bar" : "A", "baz" : { "$binary" : "ZGVhZGJlZWY=", "$type" : "04" } } ])" );
145+ }
146+
147+ TEST_CASE (" CXX-1712: Overloaded to_json Relaxed" ) {
148+ using namespace bsoncxx ;
149+ using namespace builder ::basic;
150+
151+ types::b_binary bin_val{
152+ binary_sub_type::k_uuid, 8 , reinterpret_cast <const uint8_t *>(" deadbeef" )};
153+ auto arr = make_array (make_document (kvp (" foo" , 42 ), kvp (" bar" , " A" ), kvp (" baz" , bin_val)));
154+ auto output = to_json (arr.view (), ExtendedJsonMode::k_relaxed);
155+
156+ REQUIRE (
157+ output ==
158+ R"( [ { "foo" : 42, "bar" : "A", "baz" : { "$binary" : { "base64" : "ZGVhZGJlZWY=", "subType" : "04" } } } ])" );
159+ }
160+
161+ TEST_CASE (" CXX-1712: Overloaded to_json Canonical" ) {
162+ using namespace bsoncxx ;
163+ using namespace builder ::basic;
164+
165+ types::b_binary bin_val{
166+ binary_sub_type::k_uuid, 8 , reinterpret_cast <const uint8_t *>(" deadbeef" )};
167+ auto arr = make_array (make_document (kvp (" foo" , 42 ), kvp (" bar" , " A" ), kvp (" baz" , bin_val)));
168+ auto output = to_json (arr.view (), ExtendedJsonMode::k_canonical);
169+
170+ REQUIRE (
171+ output ==
172+ R"( [ { "foo" : { "$numberInt" : "42" }, "bar" : "A", "baz" : { "$binary" : { "base64" : "ZGVhZGJlZWY=", "subType" : "04" } } } ])" );
173+ }
174+
119175TEST_CASE (" UDL _bson works like from_json()" ) {
120176 using namespace bsoncxx ;
121177
0 commit comments