title: How to serialize-deserialize any of 3 object types, one of which contains an abstract class?
body: <p>I am sending 3 .net objects over the network:</p>
  
  <pre><code> - List&lt;int&gt;
   - List&lt;ParentObject&gt;
   - string
  </code></pre>
  
  <p>This is how I'm serializing (same for all types):</p>
  
  <pre><code>JsonSerializerSettings JSsettings = new JsonSerializerSettings
          {
              TypeNameHandling = TypeNameHandling.Arrays
          };
  
          string message = JsonConvert.SerializeObject(listOfParents, JSsettings);
          //listOfParents is  of type List&lt;ParentObject&gt;
  </code></pre>
  
  <p>The ParentObject is an abstract class and has two child classes. It has a property to get which child type it represents.</p>
  
  <pre><code>public enum EntityType {Child1, Child2};
  
  class ParentObject
  {
    public EntityType et { get; set; }
    //..other members
  }
  </code></pre>
  
  <p>I want to call 3 different functions based on which of the 3 objects is received.</p>
  
  <pre><code>Object genericObject = JsonConvert.DeserializeObject(message, new JsonSerializerSettings
              {
                  TypeNameHandling = TypeNameHandling.Auto
              });
  
          if (genericObject is List&lt;int&gt;)
          {
            List&lt;int&gt; myList= (List&lt;int&gt;)genericObject;
            myfunction1(myList);
          }
          if (genericObject is List&lt;ParentObject&gt;)
          {
           //etc..
  </code></pre>
  
  <p>The ParentObject is causing problems at DeserializeObject() because it says "Could not create an instance of type ParentObject. Type is an interface or abstract class and cannot be instantiated". So I was thinking I might need to use CustomCreationConverter at <a href="http://james.newtonking.com/projects/json/help/index.html?topic=html/CustomCreationConverter.htm" rel="nofollow">http://james.newtonking.com/projects/json/help/index.html?topic=html/CustomCreationConverter.htm</a></p>
  
  <p>That still wouldn't solve my problem since the CustomCreationConverter needs the type <strong>during</strong> deserialization whereas I don't check the type until <strong>after</strong> deserialization.</p>
  
  <p>Any suggestions to solve the problem?</p>