{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/Configuration/issues/788","repository_url":"https://api.github.com/repos/aspnet/Configuration","labels_url":"https://api.github.com/repos/aspnet/Configuration/issues/788/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/Configuration/issues/788/comments","events_url":"https://api.github.com/repos/aspnet/Configuration/issues/788/events","html_url":"https://github.com/aspnet/Configuration/issues/788","id":300092117,"number":788,"title":"ConfigurationBinder binds empty array as null","user":{"login":"andrewslavin","id":6835786,"avatar_url":"https://avatars2.githubusercontent.com/u/6835786?v=4","gravatar_id":"","url":"https://api.github.com/users/andrewslavin","html_url":"https://github.com/andrewslavin","followers_url":"https://api.github.com/users/andrewslavin/followers","following_url":"https://api.github.com/users/andrewslavin/following{/other_user}","gists_url":"https://api.github.com/users/andrewslavin/gists{/gist_id}","starred_url":"https://api.github.com/users/andrewslavin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrewslavin/subscriptions","organizations_url":"https://api.github.com/users/andrewslavin/orgs","repos_url":"https://api.github.com/users/andrewslavin/repos","events_url":"https://api.github.com/users/andrewslavin/events{/privacy}","received_events_url":"https://api.github.com/users/andrewslavin/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-02-26T02:43:01Z","updated_at":"2018-02-26T10:04:44Z","closed_at":null,"author_association":"NONE","body":"Example:\r\n\r\n1. I have a class `AppSettings` with property `public string[] SomeValues { get; set; }`.\r\n1. My `appsettings.json` is `{\"SomeValues\": []}`.\r\n\r\nWhen I bind an instance of `AppSettings` to the configuration like this: `configurationBuilder.AddJsonFile(\"appsettings.json\").Build().Bind(appSettings)`, property `SomeValues` is null. I expect empty array.\r\n\r\nNote that if I change `appsettings.json` to `{\"SomeValues\": [\"val1\", \"val2\"]}`, `SomeValues` does get set to the expected string array. So generally binding is working."},"comment":{"url":"https://api.github.com/repos/aspnet/Configuration/issues/comments/368449912","html_url":"https://github.com/aspnet/Configuration/issues/788#issuecomment-368449912","issue_url":"https://api.github.com/repos/aspnet/Configuration/issues/788","id":368449912,"user":{"login":"andrewslavin","id":6835786,"avatar_url":"https://avatars2.githubusercontent.com/u/6835786?v=4","gravatar_id":"","url":"https://api.github.com/users/andrewslavin","html_url":"https://github.com/andrewslavin","followers_url":"https://api.github.com/users/andrewslavin/followers","following_url":"https://api.github.com/users/andrewslavin/following{/other_user}","gists_url":"https://api.github.com/users/andrewslavin/gists{/gist_id}","starred_url":"https://api.github.com/users/andrewslavin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrewslavin/subscriptions","organizations_url":"https://api.github.com/users/andrewslavin/orgs","repos_url":"https://api.github.com/users/andrewslavin/repos","events_url":"https://api.github.com/users/andrewslavin/events{/privacy}","received_events_url":"https://api.github.com/users/andrewslavin/received_events","type":"User","site_admin":false},"created_at":"2018-02-26T10:04:43Z","updated_at":"2018-02-26T10:04:43Z","author_association":"NONE","body":"Thanks @MichaCo. This solves the specific issue I described, but creates another. If property is declared as `public string[] SomeValues { get; set; } = new string[0];` and `appsettings.json` is `{\"SomeValues\": null}`, `SomeValues` stays as empty array. Expected null.\r\n\r\nI can obviously work around both scenarios, but the expected behaviour is that I do not have to give default values to the properties, and `ConfigurationBinder` sets them to whatever I see in `appsettings.json` (provided there are no other config sources of course).\r\n"}}
{"actor":{"display_login":"andrewslavin"}}