I have this class for settings in my console app. When i read the json file, it reads the StopBits as 2 (as expected). But when i then read Console.WriteLine(settings.ServerSettings.StopBits.ToString()); The StopBits is printed as One (not Two/2) What am i doing wrong here when i read the json to my class?
// Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(myJsonResponse);
using System.IO.Ports;
using System.Reflection;
using System.Text.Json.Serialization;
namespace Settings
{
public class ClsSettings
{
[JsonInclude]
public ComSettings ClientSettings = new();
[JsonInclude]
public ComSettings ServerSettings = new();
}
public class ComSettings
{
[JsonInclude]
public string ComSelection { get; set; } = "";
[JsonInclude]
public string ComDeviceID { get; set; } = "";
[JsonInclude]
public Int32 BaudRate = 9600;
[JsonInclude]
public Parity ComParity = Parity.None;
[JsonInclude]
public StopBits StopBits = StopBits.One;
[JsonInclude]
public int Datasize = 8;
}
}
and the JSon
{
"ClientSettings": {
"ComSelection": "",
"ComDeviceID": "",
"BaudRate": 9600,
"ComParity": 0,
"StopBits": 1,
"Datasize": 8
},
"ServerSettings": {
"ComSelection": "",
"ComDeviceID": "",
"BaudRate": 9600,
"ComParity": 0,
"StopBits": 2,
"Datasize": 8
}
}