title: Any library functions to deserialize JSON automatically and manually?
body: <p>I'm doing some work for a JIRA REST lib. It uses JSON for communication. 
  Part of the objects I receive in JSON format are know. The others can be of several different formats. So what I have done is created an object with properties that hide a dictionary</p>
  
  <pre><code>public IssueFields Fields { get; set; }
  
  public IssueType IssueType
  {
      get { return Fields.IssueType; }
      set { Fields.IssueType= value; }
  }
  
  IssueFields
  {
      private Dictionary&lt;string, Field&gt; _fields = new Dictionary&lt;string, Field&gt;();
  
      public string IssueType
      {
           get { return GetFieldByName&lt;IssueType&gt;(IssueTypeFieldName); }
           set { SetFieldByName(IssueTypeFieldName, value); }
      }
  
      public T GetFieldByName&lt;T&gt;(string fieldName) where T : class
      {
           return _fields.ContainsKey(fieldName) ? _fields[fieldName] as T: null;
      }
      public void SetFieldByName(string fieldName, Field field)
      {
           if (_fields.ContainsKey(fieldName))
           {
               _fields[fieldName] = field;
           }
           else
           {
               _fields.Add(fieldName, field);
           }
      }
  </code></pre>
  
  <p>So I have a bunch of classes like that. I can deserialize into them no problem since JavaScriptSerializer (or any other JSON deserializer) just takes the values and puts them into properties of the objects objects automatically. However there are a bunch of unknown fields all starting with "customField_XXXXX". </p>
  
  <p>What I am currently doing is overriding the JavaScriptSerializer and manually putting EVERYTHING into place. Another idea I got from someone else's code was to re-serialize the dictionary inside the JavaScriptConverter override, then deserialize it into the issue, then put everything else in manually from the dictionary, but that adds a lot of overhead and certainly will raise more than a few eyebrows. </p>
  
  <pre><code>public class MyConverter : JavaScriptConverter
  {
      private static JavaScriptSerializer _javaScriptSerializer;
  
      public override object Deserialize(IDictionary&lt;string, object&gt; dictionary, Type type, JavaScriptSerializer serializer)
      {
          string json = _javaScriptSerializer.Serialize(dictionary);
          Issue issue = _javaScriptSerializer.Deserialize&lt;Issue&gt;(json);
          // Then add the rest of my objects manually
  </code></pre>
  
  <p>Is there any way to get the object back with whatever it could serialize AND the dictionary so I can fill in anything it couldn't on my own? I just haven't been able to find anything other than this method....</p>
  
  <p>Thanks!</p>