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

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Won't Fix
    • Priority: Minor - P4
    • None
    • Affects Version/s: 2.0.1
    • Component/s: Serialization
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      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.

            Assignee:
            Unassigned
            Reporter:
            Robert Stam
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: