title: WebAPI JSON Serialization not serializing any children of a composite object
body: <p>So I am needing to serialize a composite to JSON (with JSON.NET) and was hoping that coming here with this problem would be a quick win.</p>
  
  <p>I have a very basic composite implementation that I am just trying to use to scaffold my services and the data structure but the JSONSerializer is only serializing the root node.</p>
  
  <p>Code:</p>
  
  <pre><code>namespace Data
  {   
     public abstract class Element
     {
         protected string _name;
         public Element(string name)
         {
             _name = name;
         }
         public abstract void Add(Element element);
  
  
         public string Name { get { return _name; } }
     }
  
     public class ConcreteElement : Element
     {
        public ConcreteElement(string name) : base(name) { }
        public override void Add(Element element)
        {
           throw new InvalidOperationException("ConcreteElements may not contain Child nodes. Perhaps you intended to add this to a Composite");
        }
     }
  
      public class Composite: Element
      {
         public Composite(string name) : base(name) { Elements = new List&lt;Element&gt;(); }
         private List&lt;Element&gt; Elements { get; set; }
         public override void Add(Element element)
         {
             Elements.Add(element);
         }
      }
  }
  </code></pre>
  
  <p>In my Controller's HttpGet method,</p>
  
  <pre><code>Composite root = new Composite("Root");
  Composite branch = new Composite("Branch");
  branch.Add(new ConcreteElement("Leaf1"));
  branch.Add(new ConcreteElement("Leaf2"));
  root.Add(branch);
  return JsonConvert.SerializeObject(root);
  </code></pre>
  
  <p>And the only thing that is being serialized is </p>
  
  <pre><code>{"Name\":\"Root\"}"
  </code></pre>
  
  <p>Can anyone see a reason that this is not serializing child elements?
  I'm hoping it's something stupid.</p>
  
  <h2>Edit1</h2>
  
  <p>I've never tried to Serialize a graph to JSON with WebAPI before.  Do I need to write a custom MediaTypeFormatter for serializing this? </p>
  
  <h2>Edit2 (to add desired output)</h2>
  
  <p>Leaf1 and Leaf2 are just markers at the moment. They will themselves be complex objects once I can get this to serialize.
  So, at the moment...</p>
  
  <pre><code>{
    "Name" : "Root"
    ,"Branch":  
             [
                {"Name":"Leaf1"}
               ,{"Name":"Leaf2"}
               ]
             ]
  }
  </code></pre>
  
  <p>and eventually</p>
  
  <pre><code>{
     "Name" : "Root"
    ,"Branch1":
            [
              {"Name":"Leaf1", "Foo":"Bar"}
              {"Name":"Leaf2", "Foo":"Baz"} 
            ]
   ,"Branch2":
            [
              "Branch3":[
                          {"Name":"Leaf3", "Foo":"Quux"}
                        ]
            ]
  }
  </code></pre>