nlohmann / json

JSON for Modern C++
https://json.nlohmann.me
MIT License
43.13k stars 6.73k forks source link

Can't stream json object in to std::basic_stringstream<wchar_t> #1656

Closed BrainStone closed 5 years ago

BrainStone commented 5 years ago

It is not possible to directly stream a json object into a std::basic_stringstream<wchar_t>.

(Not) working minimal example: https://wandbox.org/permlink/UPTfYGpCkteUSbDx

That the required operator overload exists, so it can be streamed into a std::basic_stringstream<wchar_t> like it can into a std::basic_stringstream<char>

The operator overload is missing resulting in a complier error.

GCC 8.3 on Debian 10 (and yes, it is supported according to the link)

Using version 3.6.1

99% tests passed, 1 tests failed out of 88

Label Time Summary:
all        = 2271.43 sec*proc (41 tests)
default    = 134.07 sec*proc (41 tests)

Total Test time (real) = 2446.36 sec

The following tests FAILED:
         80 - test-unicode_all (Timeout)
Errors while running CTest
nlohmann commented 5 years ago

This is indeed not supported in the moment. What would be the encoding of the characters in the stream? UTF-16?

BrainStone commented 5 years ago

I cannot really answer the question. Though my guess would be UTF-8.
I cannot answer it with 100% certainty because it is the stream type the https://github.com/zuhd-org/easyloggingpp library uses. Though I think they just use UTF-8. Especially considering I can use .dump() just fine.

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

BrainStone commented 5 years ago

Great to see this dying due to inactivity.

nlohmann commented 5 years ago

Sorry, but this is a part-time project. And for this issue it’s not even clear what to do.

BrainStone commented 5 years ago

The simplest solution would be to just stream a string object into it. I mean wstreams need to be able to handle that themselves. And if they don't that's not your problem.

nlohmann commented 5 years ago

But in order to do this, the characters of type char have to be converted to wchar. And this conversion would also involve encoding: how would an UTF-8 string be recoded to a sequence of wchar?

BrainStone commented 5 years ago

No. You can stream chars just fine into a "wstream". http://cpp.sh/2u7wa

nlohmann commented 5 years ago

Technically, anything can be converted to anything. But:

But in order to do this, the characters of type char have to be converted to wchar. And this conversion would also involve encoding: how would an UTF-8 string be recoded to a sequence of wchar?

I do not think such a conversion should be part of the API of the library - if needed, user code should do it, because only this code knows what a sequence of wchar should mean in this setting.

BrainStone commented 5 years ago

Again, you don't need to convert anything. Normal char based strings are just fine. Because then the stream is obligated to do the correct conversion.