I would like to sort the serialized properties with System.Text.Json. Actually, I want to put one property (ID) in the first place.
Follow my console application.
class Program
{
static void Main(string[] args)
{
Student student = new Student()
{
Name = "Robert",
Id = Guid.NewGuid(),
LastName = "Alv",
Check = "Ok"
};
var resultJson = System.Text.Json.JsonSerializer.Serialize(student);
Console.WriteLine(resultJson);
Console.ReadLine();
}
class BaseClass1
{
public Guid Id { get; set; }
}
class BaseClass2 : BaseClass1
{
}
class People : BaseClass2
{
public string Name { get; set; }
public string LastName { get; set; }
public string Check { get; set; }
}
class Student : BaseClass2
{
public string Name { get; set; }
public string LastName { get; set; }
public string Check { get; set; }
}
}
The result of the program above is {"Name":"Robert","LastName":"Alv","Check":"Ok","Id":"4bd17c0c-f610-414d-8f6c-49ca8957ef3f"}
But I want the result below
{"Id":"4bd17c0c-f610-414d-8f6c-49ca8957ef3f","Name":"Robert","LastName":"Alv","Check":"Ok"}