{"action":"created","issue":{"url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/issues/1862","repository_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json","labels_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/issues/1862/labels{/name}","comments_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/issues/1862/comments","events_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/issues/1862/events","html_url":"https://github.com/JamesNK/Newtonsoft.Json/issues/1862","id":365711190,"node_id":"MDU6SXNzdWUzNjU3MTExOTA=","number":1862,"title":"[Feature] StringEnumConverter takes a NamingStragey argument","user":{"login":"poulad","id":14295804,"node_id":"MDQ6VXNlcjE0Mjk1ODA0","avatar_url":"https://avatars0.githubusercontent.com/u/14295804?v=4","gravatar_id":"","url":"https://api.github.com/users/poulad","html_url":"https://github.com/poulad","followers_url":"https://api.github.com/users/poulad/followers","following_url":"https://api.github.com/users/poulad/following{/other_user}","gists_url":"https://api.github.com/users/poulad/gists{/gist_id}","starred_url":"https://api.github.com/users/poulad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/poulad/subscriptions","organizations_url":"https://api.github.com/users/poulad/orgs","repos_url":"https://api.github.com/users/poulad/repos","events_url":"https://api.github.com/users/poulad/events{/privacy}","received_events_url":"https://api.github.com/users/poulad/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-10-02T02:07:23Z","updated_at":"2018-10-02T21:47:11Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"### Feature - Custom naming strategy for enum-string conversions\r\n\r\nIt is not possible to use custom naming strategies when converting enum values to string. The only options are default enum value name or camel-cased names. Here is how to have snake-cased JSON strings:\r\n\r\n```c#\r\n// using System.Runtime.Serialization;\r\n// using Newtonsoft.Json;\r\n// using Newtonsoft.Json.Converters;\r\n\r\n[JsonConverter(typeof(StringEnumConverter))]\r\npublic enum Foo {\r\n  [EnumMember(Value = \"bar_baz\")]\r\n  BarBaz\r\n}\r\n```\r\n\r\nIf `StringEnumConverter` accepts `NamingStrategy` type as argument, there would be no need to specify names manually.\r\n\r\n```c#\r\n// using System.Runtime.Serialization;\r\n// using Newtonsoft.Json;\r\n// using Newtonsoft.Json.Converters;\r\n// using Newtonsoft.Json.Serialization;\r\n\r\n[JsonConverter(typeof(StringEnumConverter), typeof(SnakeCaseNamingStrategy))]\r\npublic enum Foo {\r\n  BarBaz\r\n}\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/issues/comments/426441856","html_url":"https://github.com/JamesNK/Newtonsoft.Json/issues/1862#issuecomment-426441856","issue_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/issues/1862","id":426441856,"node_id":"MDEyOklzc3VlQ29tbWVudDQyNjQ0MTg1Ng==","user":{"login":"poulad","id":14295804,"node_id":"MDQ6VXNlcjE0Mjk1ODA0","avatar_url":"https://avatars0.githubusercontent.com/u/14295804?v=4","gravatar_id":"","url":"https://api.github.com/users/poulad","html_url":"https://github.com/poulad","followers_url":"https://api.github.com/users/poulad/followers","following_url":"https://api.github.com/users/poulad/following{/other_user}","gists_url":"https://api.github.com/users/poulad/gists{/gist_id}","starred_url":"https://api.github.com/users/poulad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/poulad/subscriptions","organizations_url":"https://api.github.com/users/poulad/orgs","repos_url":"https://api.github.com/users/poulad/repos","events_url":"https://api.github.com/users/poulad/events{/privacy}","received_events_url":"https://api.github.com/users/poulad/received_events","type":"User","site_admin":false},"created_at":"2018-10-02T21:47:11Z","updated_at":"2018-10-02T21:47:11Z","author_association":"CONTRIBUTOR","body":"I see what you are worrying about.\r\n\r\n> Side Note: I first asked myself whether we really need that `allowIntegerValues` when working with a _naming strategy_ . It seems redundant, right? But it might break deserialization of some integer values that have been serialized before. In my example above, `0` won't be deserialized into `Foo.BarBaz`.\r\n\r\nThere are 3 public ctors on the type currently. The code below suggests to make them 6 for this version and finally 4 ctors will be left in the next major release.\r\n\r\n```c#\r\npublic StringEnumConverter()\r\npublic StringEnumConverter(Type namingStrategyType)\r\npublic StringEnumConverter(Type namingStrategyType, bool allowIntegerValues)\r\npublic StringEnumConverter(NamingStrategy strategy)\r\npublic StringEnumConverter(NamingStrategy strategy, bool allowIntegerValues)\r\n\r\n\r\n[Oboslete] public StringEnumConverter(bool camelCaseText)\r\n[Obsolete] public StringEnumConverter(bool camelCaseText, bool allowIntegerValues)\r\n```\r\n\r\nGoing this way, that `allowIntegerValues`, when used in conjunction with a naming strategy, will serve as a backwards-compatible solution to allow deserializations of numeric values only."}}
{"actor":{"display_login":"poulad"}}