title: JSON.Net throws StackOverflowException when using [JsonConvert()]
body: <p>I wrote this simple code to Serialize classes as flatten, but when I use <code>[JsonConverter(typeof(FJson))]</code> annotation, it throws a <em>StackOverflowException</em>.  If I call the <code>SerializeObject</code> manually, it works fine.</p>
  
  <p>How can I use JsonConvert in Annotation mode:</p>
  
  <pre><code>class Program
      {
          static void Main(string[] args)
          {
              A a = new A();
              a.id = 1;
              a.b.name = "value";
  
              string json = null;
  
              // json = JsonConvert.SerializeObject(a, new FJson()); without [JsonConverter(typeof(FJson))] annotation workd fine
              // json = JsonConvert.SerializeObject(a); StackOverflowException
  
              Console.WriteLine(json);
              Console.ReadLine();
          }
      }
  
      //[JsonConverter(typeof(FJson))] StackOverflowException
      public class A
      {
          public A()
          {
              this.b = new B();
          }
  
          public int id { get; set; }
          public string name { get; set; }
          public B b { get; set; }
      }
  
      public class B
      {
          public string name { get; set; }
      }
  
      public class FJson : JsonConverter
      {
          public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
          {
              JToken t = JToken.FromObject(value);
              if (t.Type != JTokenType.Object)
              {
                  t.WriteTo(writer);
                  return;
              }
  
              JObject o = (JObject)t;
              writer.WriteStartObject();
              WriteJson(writer, o);
              writer.WriteEndObject();
          }
  
          private void WriteJson(JsonWriter writer, JObject value)
          {
              foreach (var p in value.Properties())
              {
                  if (p.Value is JObject)
                      WriteJson(writer, (JObject)p.Value);
                  else
                      p.WriteTo(writer);
              }
          }
  
          public override object ReadJson(JsonReader reader, Type objectType,
             object existingValue, JsonSerializer serializer)
          {
              throw new NotImplementedException();
          }
  
          public override bool CanConvert(Type objectType)
          {
              return true; // works for any type
          }
      }
  </code></pre>