title: Deserializing an object with a Dictionary<string, object> property (Newtonsoft.Json)
body: <p>I have an object like this:</p>
  
  <pre><code>public class Context
  {
      public Dictionary&lt;string, object&gt; Arguments { get; set; }
  }
  </code></pre>
  
  <p>I serialize it using this method:</p>
  
  <pre><code>private static string Serialize(object obj)
  {
      return JsonConvert.SerializeObject(obj, new JsonSerializerSettings
      {
          TypeNameHandling = TypeNameHandling.All
      });
  }
  </code></pre>
  
  <p>I deserialize it like this:</p>
  
  <pre><code>public Context DesirializeContext
  {
      get
      {
          return JsonConvert.DeserializeObject&lt;EventContext&gt;(Context, new JsonSerializerSettings
          {
              TypeNameHandling = TypeNameHandling.All
          });
      }
  }
  </code></pre>
  
  <p>The problem is that when I try to deserialize it, the values in the dictionary don't have the correct type.</p>
  
  <p>For example, if I have {"key1", 1} and {"key2", objectb}, after deserialization, the types of the values will be Int64 and Newtonsoft.Json.Linq.JArray.</p>
  
  <p>Now I know I can use the below code to cast a value to a target object (my target type in this case is a DataTable)</p>
  
  <pre><code>(DataTable)JsonConvert.DeserializeObject(Arguments["SubstituteData"].ToString(), typeof(DataTable));
  </code></pre>
  
  <p>But is there anyway to automatically cast the values in the dictionary to their original type when desirializing? This would make things much easier.</p>