title: C++ JSON Serialization
body: <p>I want a way to serialize and deserialize Objects to JSON, as automatic as possible.</p>
  
  <p><strong>Serialize:</strong>
  For me, the ideal way is that if I call in an instance JSONSerialize() it returns an string with a JSON object that has all the public properties of the object as <code>"name_of_property": "value"</code>.
  For those values that are primitives, it is straightforward, for objects it should try to call on each JSONSerialize() or ToString() or something like that to recursively serialize all the public properties.
  For collections it should also behave correctly (just vectors/arrays will be ok).</p>
  
  <p><strong>Deserialize</strong>: Just make an instance of the given object (let's say a dog) and call <code>JSONDeserialize(json_string)</code>, and that should fill all the public properties, creating the needed objects in case that the properties are not primitives, or the needed collections.</p>
  
  <p>An example should run like that:</p>
  
  <pre><code>Dog *d1 = new Dog();
  d1-&gt;name = "myDog";
  
  string serialized = d1-&gt;JSONSerialize();
  
  Dog *d2 = new Dog();
  d2-&gt;JSONDeserialize(serialized);
  std::cout &lt;&lt; d2-&gt;name; // This will print "myDog"
  </code></pre>
  
  <p>Or like that:</p>
  
  <pre><code>Dog *d1 = new Dog();
  d1-&gt;name = "myDog";
  
  string serialized = JSONSerializer.Serialize(d1);
  
  Dog *d2 = JSONSerializer.Deserialize(serialized, Dog);
  std::cout &lt;&lt; d2-&gt;name; // This will print "myDog"
  </code></pre>
  
  <p>How can I pull this off easily?</p>