Is there a way to make the output of serialized JSON match the order of the items in the class?
I looked around in the JSON library already and I think this is because of the usage of a hashtable, which doesnt store the order you put in items but stores them in hashed order.
I can’t really oversee if it would be possible to use something else than a hashtable?
The reason I’m asking is because we use the JSON library for our settings system and some settings classes are very big and it’s very hard and inconvenient to browse the settings when they are this much out of order.
For example:
This settings class
public class SettingsFile : SettingsBase
{
public override string FileName { get; set; } = "settings.json";
public int ModuleId = 1;
public int CanOutBaudrate = 250_000;
public int Baudrate1 = 4800;
public int Baudrate2 = 4800;
public int Baudrate3 = 4800;
public int Baudrate4 = 4800;
public bool UseAnalogRotForTransversal = false;
public string AnalogRotId = "0x16E40001";
public bool DoFuelRate = false;
public int SbMainEngineId = 1;
public int PsMainEngineId = 2;
public int SbGenEngineId = 3;
public int PsGenEngineId = 4;
public int BowGenEngineId = 5;
public int LedTimeOut = 1000;
public int YOffset = 0;
public int XBowOffset = 0;
public int XRearOffset = 0;
public int XOffset = 0;
}
Gets serialized into:
{
"ModuleId": 10,
"Baudrate1": 115200,
"PsMainEngineId": 2,
"SbMainEngineId": 1,
"PsGenEngineId": 4,
"Password": "40TA96/?",
"DNS": "192.168.1.1",
"CanOutBaudrate": 250000,
"Gateway": "192.168.1.1",
"DoFuelRate": false,
"FileName": "settings.json",
"UseAnalogRotForTransversal": true,
"XRearOffset": 0,
"UpdateMode": false,
"CommandSocketPort": 5050,
"BowGenEngineId": 5,
"Baudrate2": 4800,
"LedTimeOut": 1000,
"Baudrate4": 4800,
"YOffset": 0,
"SbGenEngineId": 3,
"IP": "192.168.31.59",
"XOffset": 0,
"AnalogRotId": "0x16E4000A",
"SubnetMask": "255.255.255.0",
"XBowOffset": 0,
"EnableWatchdog": false,
"Baudrate3": 4800
}