Order of fields when serializing the derived class in JSON.NET

Just as a complement, another approach different than the accepted answer is using [JsonProperty(Order = -2)]; You can modify your base class as follow:

public class Base
{
    [JsonProperty(Order = -2)]
    public string Id { get; set; }

    [JsonProperty(Order = -2)]
    public string Name { get; set; }

    [JsonProperty(Order = -2)]
    public string LastName { get; set; }
}

The reason of setting Order values to -2 is that every property without an explicit Order value has a value of -1 by default. So you need to either give all child properties an Order value, or just set your base class’ properties to -2.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)