title: Accept null values for strings with rapidjson inside cereal, make them ""
body: <p>For deserializing JSON into a c++ class, I'm using Cereal, which uses RapidJSON. As expected, c++ std::string can't have a null value. But other platforms do support null for strings (.NET SQL etc) and I get JSON from them with null values for strings. I need to tolerate this, and just make an empty string for nulls. What's the best way to do that?</p>
  
  <p>I default to string substitute on the JSON changing nulls to "" like the following, but it is not a clean solution.</p>
  
  <pre><code>#include &lt;cereal/archives/json.hpp&gt;
  #include &lt;boost/algorithm/string.hpp&gt;
  // i.e. substitue all ":null with ":"" Like {"key":null} into {"key":""}
  boost::replace_all(json, "\":null", "\":\"\""); 
  auto r = std::make_shared&lt;R&gt;();
  std::stringstream ss(json);
  {
      cereal::JSONInputArchive archive(ss);
      r-&gt;serialize(archive);
  }
  </code></pre>
  
  <p>In case someone looks for this answer based on the exception generated by Cereal, it is: "rapidjson internal assertion failure: IsString()"</p>