I'm using .NET Core and want to configure my options. Based on this sample class
public class MySettings
{
public Dictionary<int, string> Mapping { get; set; }
}
I added a mapping to the appsettings.json file
{
"MySettings": {
"Mapping": {
"9454545": "agf51528gfhdfg",
"13544": "bfds28745hfghsdfghd"
}
}
}
but as you can see the keys are of type string, not integers. It is not possible for me to change the property names to numbers because then I get the error
JSON property names should be strings. Numeric property names are not allowed in JSON
So when calling this in the startup file
IConfigurationSection mySettingsSection = configuration.GetSection("MySettings");
services.Configure<MySettings>(mySettingsSection);
the field Mapping will have 0 items because it is not able to parse the JSON keys to integers automatically. Is there a way I can tell .NET Core to parse those string keys to integers and fill up the dictionary?