Consider these two classes:
public Class Base {
public string Id {get; set;}
public string Name {get; set;}
public string LastName {get; set;}
}
And the derived class:
public Class Derived : Base {
public string Address {get; set;}
public DateTime DateOfBirth {get; set;}
}
When serializing the Derived class using Json.Net:
Derived record = new Derived record(); {// Initialize here...}
JsonConvert.SerializeObject(record);
By default, the properties of the Derived class appear first:
{
"address": "test",
"date_of_birth" : "10/10/10",
"id" : 007,
"name" : "test name",
"last_name": "test last name"
}
What I need:
{
"id" : 007,
"name" : "test name",
"last_name": "test last name"
"address": "test",
"date_of_birth" : "10/10/10",
}
Question
Is it possible to have the base class properties come first, when serializing the derived class (without using [JsonProperty(Order=)]
for each property of both classes)?
JToken.DeepEquals
to be very useful, it eliminates differences due purely to formatting. – Joann