title: Custom JsonConverter WriteJson Does Not Alter Serialization of Sub-properties
body: <p>I always had the impression that the JSON serializer actually traverses your entire object's tree, and executes the custom JsonConverter's WriteJson function on each interface-typed object that it comes across - not so.</p>
  
  <p>I have the following classes and interfaces:</p>
  
  <pre><code>public interface IAnimal
  {
      string Name { get; set; }
      string Speak();
      List&lt;IAnimal&gt; Children { get; set; }
  }
  
  public class Cat : IAnimal
  {
      public string Name { get; set; }
      public List&lt;IAnimal&gt; Children { get; set; }        
  
      public Cat()
      {
          Children = new List&lt;IAnimal&gt;();
      }
  
      public Cat(string name="") : this()
      {
          Name = name;
      }
  
      public string Speak()
      {
          return "Meow";
      }       
  }
  
   public class Dog : IAnimal
   {
      public string Name { get; set; }
      public List&lt;IAnimal&gt; Children { get; set; }
  
      public Dog()
      {
          Children = new List&lt;IAnimal&gt;();   
      }
  
      public Dog(string name="") : this()
      {
          Name = name;
      }
  
      public string Speak()
      {
          return "Arf";
      }
  
  }
  </code></pre>
  
  <p>To avoid the $type property in the JSON, I've written a custom JsonConverter class, whose WriteJson is</p>
  
  <pre><code>public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
  {
      JToken t = JToken.FromObject(value);
  
      if (t.Type != JTokenType.Object)
      {
          t.WriteTo(writer);                
      }
      else
      {
          IAnimal animal = value as IAnimal;
          JObject o = (JObject)t;
  
          if (animal != null)
          {
              if (animal is Dog)
              {
                  o.AddFirst(new JProperty("type", "Dog"));
                  //o.Find
              }
              else if (animal is Cat)
              {
                  o.AddFirst(new JProperty("type", "Cat"));
              }
  
              foreach(IAnimal childAnimal in animal.Children)
              {
                  // ???
              }
  
              o.WriteTo(writer);
          }
      }
  }
  </code></pre>
  
  <p>In this example, yes, a dog can have cats for children and vice-versa. In the converter, I want to insert the "type" property so that it saves that to the serialization. I have the following setup. (Zoo has only a name and a list of IAnimals. I didn't include it here for brevity and laziness ;)) </p>
  
  <pre><code>Zoo hardcodedZoo = new Zoo()
              {   Name = "My Zoo",               
                  Animals = new List&lt;IAnimal&gt; { new Dog("Ruff"), new Cat("Cleo"),
                      new Dog("Rover"){
                          Children = new List&lt;IAnimal&gt;{ new Dog("Fido"), new Dog("Fluffy")}
                      } }
              };
  
              JsonSerializerSettings settings = new JsonSerializerSettings(){
                  ContractResolver = new CamelCasePropertyNamesContractResolver() ,                    
                  Formatting = Formatting.Indented
              };
              settings.Converters.Add(new AnimalsConverter());            
  
              string serializedHardCodedZoo = JsonConvert.SerializeObject(hardcodedZoo, settings);
  </code></pre>
  
  <p><code>serializedHardCodedZoo</code> has the following output after serialization:</p>
  
  <pre><code>{
    "name": "My Zoo",
    "animals": [
      {
        "type": "Dog",
        "Name": "Ruff",
        "Children": []
      },
      {
        "type": "Cat",
        "Name": "Cleo",
        "Children": []
      },
      {
        "type": "Dog",
        "Name": "Rover",
        "Children": [
          {
            "Name": "Fido",
            "Children": []
          },
          {
            "Name": "Fluffy",
            "Children": []
          }
        ]
      }
    ]
  }
  </code></pre>
  
  <p>The type property shows up on Ruff, Cleo, and Rover, but not for Fido and Fluffy. I guess the WriteJson isn't called recursively. How do I get that type property there? </p>
  
  <p>As an aside, why does it not camel-case IAnimals like I expect it to?</p>