I am posting json string to my method and getting error while deserializing to my class.
Error:
Error converting value -1 to type 'System.Nullable`1[System.UInt64]'. Path 'MyMappings1.MySqlColumns[7].size'. Inner Exception : {"Value was either too large or too small for a UInt64."}
Below is my class in which I want to output after deserializing json value :
public class MyMappings
{
public string Name { get; set; }
public List<MysqlColumns> MySqlColumns { get; set; }
}
public class MySqlColumns
{
public string Column { get; set; }
public string Datatype { get; set; }
public string IsNullable { get; set; }
public UInt64? Size { get; set; }
public UInt64? NumericPrecision { get; set; }
public UInt64? NumericScale { get; set; }
}
string myJson = "MyMappings": [
{
"Name": "dbo.Table1",
"MySqlColumns": [
{
"Name": "Address",
"datatype": "nvarchar",
"isNullable": "YES",
"size": -1,
"numericPrecision": null,
"numericScale": null
}]
var deserializeData = JsonConvert.DeserializeObject<MyMappings>(myJson);
Now when user set nvarchar(max) for any columns then I set size as -1 which is setinel value to represent max size. Now reason for setting size as -1 is because while reading column whose size is nvarchar(max) I get setinel value as -1 as per Marc Gravell's comment
I have seen this answer but my question is how do I use it while deserialization. I am using NewtonSoft json.
Update
Reason for specifying size as uint: