title: Deserialize json with known and unknown fields
body: <p>Given following json result:
  The default json result has a known set of fields:</p>
  
  <pre><code>{
      "id": "7908",
      "name": "product name"
  }
  </code></pre>
  
  <p>But can be extended with additional fields (in this example <code>_unknown_field_name_1</code> and <code>_unknown_field_name_2</code>) of which the names are not known when requesting the result.</p>
  
  <pre><code>{
      "id": "7908",
      "name": "product name",
      "_unknown_field_name_1": "some value",
      "_unknown_field_name_2": "some value"
  }
  </code></pre>
  
  <p>I would like the json result to be serialized and deserialized to and from a class with properties for the known fields and map the unknown fields (for which there are no properties) to a property (or multiple properties) like a dictionary so they can be accessed and modified.</p>
  
  <pre><code>public class Product
  {
      public string id { get; set; }
      public string name { get; set; }
      public Dictionary&lt;string, string&gt; fields { get; set; }
  }
  </code></pre>
  
  <p>I think I need a way to plug into a json serializer and do the mapping for the missing members myself (both for serialize and deserialize).
  I have been looking at various possibilities:</p>
  
  <ul>
  <li>json.net and custom contract resolvers (can't figure out how to do it)</li>
  <li>datacontract serializer (can only override onserialized, onserializing)</li>
  <li>serialize to dynamic and do custom mapping (this might work, but seems a lot of work)</li>
  <li>let product inheriting from DynamicObject (serializers work with reflection and do not invoke the trygetmember and trysetmember methods)</li>
  </ul>
  
  <p>I'm using restsharp, but any serializer can be plugged in.</p>
  
  <p>Oh, and I cannot change the json result, and <a href="https://stackoverflow.com/questions/6843754/deserializing-json-with-unknown-fields">this</a> or <a href="https://stackoverflow.com/questions/13072447/how-to-deserialize-variable-size-json-string-with-variable-names">this</a> didn't help me either.</p>
  
  <p><strong>Update:</strong>
  This looks more like it: <a href="http://geekswithblogs.net/DavidHoerster/archive/2011/07/26/json.net-custom-convertersndasha-quick-tour.aspx" rel="noreferrer">http://geekswithblogs.net/DavidHoerster/archive/2011/07/26/json.net-custom-convertersndasha-quick-tour.aspx</a></p>