[CSHARP-1393] Members should be serialized in the order they are declared in the class Created: 01/Sep/15  Updated: 18/Mar/19  Resolved: 18/Mar/19

Status: Closed
Project: C# Driver
Component/s: Serialization
Affects Version/s: 2.0.1
Fix Version/s: None

Type: Improvement Priority: Minor - P4
Reporter: Robert Stam Assignee: Unassigned
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Given this class:

public class C
{
    private readonly int _id;
    private int _x;
 
    public C(int id)
    {
        _id = id;
    }
 
    public int Id
    {
        get { return _id; }
    }
 
    public int X
    {
        get { return _x; }
        set { _x = value; }
    }
}

The values are currently being serialized as:

{ "X" : 2, "_id" : 1 }

One might expect that since Id is declared before X in the class, that it should be serialized as:

{ "_id" : 1, "X" : 2 }

In general you should write code that doesn't depend on the order of the elements, but sometimes the order might matter.

We are undecided whether this matters or not. Please comment on the ticket if this matters to you.



 Comments   
Comment by Ian Whalen (Inactive) [ 18/Mar/19 ]

If it doesn't work like this already then we're not planning to change it given the lack of activity on this ticket.

Generated at Wed Feb 07 21:39:27 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.