-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
to/from_msgpack only works with standard typization #1021
Comments
Could you provide a small example that triggers the error? |
I am working on it. #include <iostream>
#include "json.hpp"
// using json=nlohmann::json;
using json=nlohmann::basic_json<std::map, std::vector, std::string, bool, std::int32_t, std::uint32_t, float>;
int main()
{
double Value2 = 1000.0;
json j;
j["Key1"] = "Value1";
j["Key2"] = Value2;
std::vector<uint8_t> v = json::to_msgpack(j);
json k = json::from_msgpack(v);
std::cout << k.dump(4) << std::endl;
return 0;
}
Is nlohmann::json supposed to safely convert types where necessary? This one throws nlohmann::detail::parse_error |
The issue is that while the library respects the provided number types in the serialization, it does not add the correct prefixes. For instance, it serializes the To fix this issue, the serialization must derive the MessagePack (and most probably also CBOR and UBJSON) type prefix from the templated type. I am not sure about a nice way, but I think functions like |
I opened branch https://github.com/nlohmann/json/tree/feature/issue1021 which supports @phyz777 Could you check if this fixes your issue? |
@phyz777 Could you check if this fixes your issue? |
I merged the fix. If there is still an issue, please let me know. |
The to/from_msgpack functions only work for standard typization of nlohmann::basic_json.
Using nlohmann::basic_json<std::map, std::vector, std::string, bool, std::int32_t, std::uint32_t, float> produces the following error:
parse error at 1472: expected a MessagePack string; last byte: 0x68
The error occurs when I put an object into a msgpack, send it over the network, then reconstruct the object using from_msgpack. When I use nlohmann::json instead, everything works fine.
System is linux, compiler is g++, version 7.2.1, nlohmann::json is version 3.1.2.
The text was updated successfully, but these errors were encountered: