0

I have an issue with serializing the binary data when the bytes are greater 127 (0x7f). It looks like an upper bit is cut out so I get 0x7f when I want to read 0xff.

Example:

using boost::property_tree::ptree;

ptree pt;
pt.put ("binary", "\xff");

std::stringstream buf;
write_json (buf, pt);

// The JSON looks fine in this case, 
// something like { "binary": "\uFFFF" }

ptree pt2;
read_json (buf, pt2);
std::string binary = pt2.get<std::string> ("binary");
// I got 0x7f in binary[0] instead of 0xff

Is this a known issue? Any workaround?

  • It's a known issue that Boost.PropertyTree is *not for serializing data!* It's for storing options and so forth; stop using it as a quick-and-dirty JSON parser or serialization library. Use the right tool for the right job. – Nicol Bolas Oct 17 '17 at 20:42
  • Is there any other boost serialization library for JSON? – Sergey Emantayev Oct 18 '17 at 06:27
  • 2
    You can find C++ JSON libraries easily; they don't have to be part of Boost. – Nicol Bolas Oct 18 '17 at 14:20

0 Answers0