-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Labels
Description
In my experience most 3rd party libraries use std::string and not std::wstring in their interface. Therefore applications become tied to std::string. Because the ppl/json library uses std::wstring (on windows) this makes integrating the ppl/json library into an applications cumbersome and inefficient. One has to do lots of unnecessary wstring-to-string and string-to-wstring conversions. Could you add support for std::string, at least for the json library?
Minimal example:
#include <cpprest/json.h>
std::string SerializeToJson(std::string name, int id) //utf8 coming in and goin out
{
utility::stringstream_t stream;
web::json::value js_obj;
js_obj[L"id"] = web::json::value::number(id);
js_obj[L"name"] = web::json::value::string(utility::conversions::utf8_to_utf16(name)); //unneccessary conversion 1
js_obj.serialize(stream);
std::wstring wret = stream.str();
std::string ret = utility::conversions::utf16_to_utf8(wret); //unneccessary conversion 2
return ret;
}
int main() {
auto r = SerializeToJson("test", 123);
std::cout << r << std::endl;
}
jbmercha, netkeep80, capsocrates, juanchopanza, FelixSchwarz and 3 more