when I was learning Newtonsoft JSON I used the following to serialize an object:
public сlass Foo
{
public Bar Bar { get; set; }
}
public class Bar
{
public string Title { get; set; }
}
var foo = new Foo();
JsonConvert.SerializeObject(foo, Formatting.Indented);
The result is { "Bar": null }
but I would like to print { "Bar": { "Title": null } }
without creating an instance of Bar.
I used the solution of ServiceStack (the Dump method) and returned an empty object. Maybe overload a method in the DefaultContractResolver?