title: Serializing an interface/abstract object using NewtonSoft.JSON
body: <p>One way of deserializing interface and abstract properties is a class is by setting TypeNameHandling to Auto during serialization and deserialization. However, when I try the same when serializing and deserializing an interface object directly, it does not work -</p>
  
  <pre><code>interface ISample
  {
      string Key { get; set; }
  }
  
  class A : ISample
  {
      public string Key { get; set; }
  
      public A(string key)
      {
          this.Key = key;
      }
  }
  
  class B : ISample
  {
      public string Key { get; set; }
  
      public B(string key)
      {
          this.Key = key;
      }
  }
  </code></pre>
  
  <p>Serialization and deserialization code -</p>
  
  <pre><code>ISample a = new A("keyA");
  ISample b = new B("keyB");
  
  var settings = new JsonSerializerSettings();
  settings.TypeNameHandling = TypeNameHandling.Auto;
  
  var stringA = JsonConvert.SerializeObject(a, settings);
  var stringB = JsonConvert.SerializeObject(b, settings);
  
  Console.WriteLine(stringA);
  Console.WriteLine(stringB);
  
  a = JsonConvert.DeserializeObject&lt;ISample&gt;(stringA, settings);
  b = JsonConvert.DeserializeObject&lt;ISample&gt;(stringB, settings);
  </code></pre>
  
  <p>I noticed that even when setting TypeNameHandling.Auto the type information is not present in the serialized string. However, settings TypeNameHandling to Object or All works. </p>
  
  <p>Am I missing something basic here?</p>