Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-1393

Members should be serialized in the order they are declared in the class

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Won't Fix
    • Icon: Minor - P4 Minor - P4
    • None
    • 2.0.1
    • Serialization
    • None

    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.

      Attachments

        Activity

          People

            Unassigned Unassigned
            robert@mongodb.com Robert Stam
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: