Exemple #1
0
 nlohmann::json collection::convert_to_json(std::shared_ptr<bson> const& value)
 {
     char* buffer;
     int size = 0;
     bson2json(bson_data(value.get()), &buffer, &size);
     return nlohmann::json::parse(std::string(buffer, size));
 }
Exemple #2
0
void testTicket135(void) {
    bson bo_test;
    bson_init(&bo_test);
    bson_append_int(&bo_test, "myInt", 10);
    bson_append_double(&bo_test, "myDouble", -50.0);
    bson_finish(&bo_test);

    char* buf = NULL;
    int lenght = 0;
    bson2json(bson_data(&bo_test), &buf, &lenght);
    CU_ASSERT_PTR_NOT_NULL_FATAL(buf);
    CU_ASSERT_PTR_NOT_NULL(strstr(buf, "\"myInt\" : 10"));
    CU_ASSERT_PTR_NOT_NULL(strstr(buf, "\"myDouble\" : -50.000000"));
    bson_destroy(&bo_test);
    TCFREE(buf);
}