In my POCO objects, I often inherit from other POCO objects. When I serialize a POCO object using JSON.NET, the order of the properties gets messed up.
Let's say I have a Person class that looks like this:
public class Person { public int Id {get; set;} public string FirstName {get; set;} public string LastName {get; set;} }
Then I have an Employee class that inherits from the Person class:
public class Employee : Person { public int DepartmentId {get; set;} public string Title {get; set;} }
When I serialize the Employee class, my JSON object looks like this:
{ "departmentId": 123, "title": "Manager", "id": 1234567, "firstName": "John", "lastName": "Smith" }
Two questions:
- Does the order of my properties of the JSON object know?
- Even if the order of the properties does not matter, how can I make the properties be in the correct order, that is, I would like to see the properties of the Person class first, and then the properties of the Employee class.
Thank you for your help.
Sam
source share