For example I have classes:
public class ParentClass
{
public int Value1 {get; set;} = 1;
public int Value2 {get; set;} = 2;
public InnerClass InnClass {get; set;} = new InnerClass();
}
public class InnerClass
{
public int Value3 {get; set;} = 3;
public int Value4 {get; set;} = 4;
}
When I serialize an instance of the ParentClass
public ParentClass parClass = new ParentClass();
string result = JsonConvert.SerializeObject(parClass);
it returns Json:
“{“Value1”: 1, “Value2”: 2, “InnClass”: {“Value3”: 3, “Value4”: 4}}”
How to make it serialize like this:
“{“Value1”: 1, “Value2”: 2, “Value3”: 3, “Value4”: 4}”
I know that the easiest way is just to move properties from inner class to the parent class, and then to serialize it. But it will break the structure of the program. So is it any way to do this with a custom JsonConverter or other way?