The following code:
using Newtonsoft.Json;
using System.ComponentModel;
// Serialize
Dictionary<string, MyClass> d = new Dictionary<string, MyClass>();
MyClass obj = new MyClass { Id = 1, Name = "John Doe" };
d["A"] = obj;
string json = JsonConvert.SerializeObject(d);
Console.WriteLine(json);
public class B
{
public int x { get; set; }
}
[TypeConverter(typeof(ExpandableObjectConverter))]
public class MyClass
{
public int Id { get; set; }
public string Name { get; set; }
public B b { get; set; } = new B();
}
Failed to serialize MyClass and only show "MyClass" not data, due to the TypeConverter. But I need it for PropertyGrid showing. Any simple way to ignore the TypeConverter when serialized?
Thanks to @dbc, following code is desired: