I've been playing with strongly-typed configuration in .NET Core and I've found some weird behavior.
POCO
public class ModuleConfiguration
{
[JsonProperty("menu")]
public List<MenuItem> MenuItems { get; set; }
}
Settings.json
{
"moduleConfiguration": {
"menu": [
{
"id": 1,
"name": "test"
}
]
}
}
When I load the configuration:
var builder = new ConfigurationBuilder().AddJsonFile(path);
var config = builder.Build().GetSection("moduleConfiguration").Get<T>();
the MenuItems collection is null, but if I change "menu" to "menuItems" (in settings.json), the collection is populated correctly.
Does it mean that JsonProperty attribute is being ignored?
See Question&Answers more detail:os