{"id":15655101,"url":"https://github.com/stefh/system.text.json.enumextensions","last_synced_at":"2025-04-15T11:08:10.579Z","repository":{"id":45181272,"uuid":"214789523","full_name":"StefH/System.Text.Json.EnumExtensions","owner":"StefH","description":"An extended version from the JsonStringEnumConverter which supports attributes like EnumMember, Display and Description","archived":false,"fork":false,"pushed_at":"2024-07-09T21:22:37.000Z","size":39,"stargazers_count":25,"open_issues_count":4,"forks_count":4,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-15T11:08:00.298Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/StefH.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null},"funding":{"github":["StefH"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":"https://www.paypal.me/stefheyenrath"}},"created_at":"2019-10-13T08:58:13.000Z","updated_at":"2024-05-17T15:42:53.000Z","dependencies_parsed_at":"2023-12-15T00:46:33.469Z","dependency_job_id":null,"html_url":"https://github.com/StefH/System.Text.Json.EnumExtensions","commit_stats":{"total_commits":19,"total_committers":4,"mean_commits":4.75,"dds":0.368421052631579,"last_synced_commit":"a5e230d777b06d1fb0b1df1df673c50e44b7933f"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StefH%2FSystem.Text.Json.EnumExtensions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StefH%2FSystem.Text.Json.EnumExtensions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StefH%2FSystem.Text.Json.EnumExtensions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StefH%2FSystem.Text.Json.EnumExtensions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/StefH","download_url":"https://codeload.github.com/StefH/System.Text.Json.EnumExtensions/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249058370,"owners_count":21205910,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-03T12:56:19.096Z","updated_at":"2025-04-15T11:08:10.558Z","avatar_url":"https://github.com/StefH.png","language":"C#","funding_links":["https://github.com/sponsors/StefH","https://www.paypal.me/stefheyenrath"],"categories":[],"sub_categories":[],"readme":"# System.Text.Json.Extensions\nSome extensions to the JsonStringEnumConverter which supports attributes like EnumMember, Display and Description\n\n\n## Info\n| | |\n|-|-|\n| \u0026nbsp;\u0026nbsp;**Build Azure** | [![Build Status](https://dev.azure.com/stef/System.Text.Json.EnumExtensions/_apis/build/status/StefH.System.Text.Json.EnumExtensions?branchName=refs%2Fpull%2F7%2Fmerge)](https://dev.azure.com/stef/System.Text.Json.EnumExtensions/_build/latest?definitionId=28\u0026branchName=refs%2Fpull%2F7%2Fmerge) |\n| \u0026nbsp;\u0026nbsp;**NuGet** | [![NuGet: EnumExtensions.System.Text.Json](https://buildstats.info/nuget/EnumExtensions.System.Text.Json)](https://www.nuget.org/packages/EnumExtensions.System.Text.Json)\n| \u0026nbsp;\u0026nbsp;**MyGet (preview)** | [![MyGet: EnumExtensions.System.Text.Json](https://buildstats.info/myget/system_text_json_enumextensions/EnumExtensions.System.Text.Json?includePreReleases=true)](https://www.myget.org/feed/system_text_json_enumextensions/package/nuget/EnumExtensions.System.Text.Json) |\n\n\n## Installing\nYou can install from NuGet using the following command in the package manager window:\n\n`Install-Package EnumExtensions.System.Text.Json`\n\nOr via the Visual Studio NuGet package manager.\n\nIf you use the `dotnet` command:\n\n`dotnet add package EnumExtensions.System.Text.Json`\n\n\n## Option 1: Usage Example - EnumMember\n\n### Define Enum and add attributes\nDefine an Enum and annotate the Enum fields with the [EnumMemberAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.serialization.enummemberattribute?view=netstandard-2.0):\n``` c#\nenum WeatherType\n{\n    [EnumMember(Value = \"Zonnig\")]\n    Sunny,\n\n    [EnumMember(Value = \"Helder\")]\n    Clear\n}\n```\n\n### Add Converter\nAdd the new `JsonStringEnumConverterWithAttributeSupport` to the Converters via the JsonSerializerOptions:\n``` c#\nvar options = new JsonSerializerOptions();\noptions.Converters.Add(new JsonStringEnumConverterWithAttributeSupport());\n```\n\n### Serialize an object\n``` c#\nvar weatherForecast = new WeatherForecast\n{\n    WeatherType = WeatherType.Sunny\n};\n\nvar weatherForecastSerialized = JsonSerializer.Serialize(weatherForecast, options);\nConsole.WriteLine(weatherForecastSerialized); // {\"WeatherType\":\"Zonnig\"}\n```\n\n### Deserialize an object\nDeserialize works by using the same **options**:\n``` c#\nvar json = \"{\\\"WeatherType\\\":\\\"Zonnig\\\"}\";\nvar weatherForecastDeserialized = JsonSerializer.Deserialize\u003cWeatherForecast\u003e(json, options);\n```\n\n\n## Option 2: Usage Example - EnumMember\nIt's also possible to annotate the Enum with a `[JsonConverter]` so that you don't need to manually registerd the `JsonStringEnumConverterWithAttributeSupport` to the Converters via the JsonSerializerOptions.\n\n### Define Enum and add attributes\nDefine an Enum\n- add the `[JsonConverter(typeof(JsonStringEnumConverterWithAttributeSupport))]` to the Enum\n- annotate the Enum fields with the [EnumMemberAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.serialization.enummemberattribute?view=netstandard-2.0):\n``` c#\n[JsonConverter(typeof(JsonStringEnumConverterWithAttributeSupport))]\nenum WeatherType\n{\n    [EnumMember(Value = \"Zonnig\")]\n    Sunny,\n\n    [EnumMember(Value = \"Helder\")]\n    Clear\n}\n```\n\n### Serializing and Deserialize an object\nThis works the same as using Option 1.\n\nNote that only Enum values which are annotated with `EnumMember` are supported.\n\n\n## Usage Example - Display and Description\nIt's also possible to annotate Enum fields with these attributes:\n- [DisplayAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.dataannotations.displayattribute?view=netframework-4.8)\n- [DescriptionAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.descriptionattribute?view=netframework-4.8)\n\n\n### Define Enum and add attributes\n``` c#\nenum WeatherType\n{\n    [EnumMember(Value = \"Zonnig\")]\n    Sunny,\n\n    [Display(Name = \"Helder\")]\n    Clear,\n\n    [Description(\"Bewolkt\")]\n    Cloudy\n}\n```\n\n### Add Converter\n**!** By default, the Display and Description are disabled, use the following line to enable these.\n``` c#\nvar options = new JsonSerializerOptions();\noptions.Converters.Add(new JsonStringEnumConverterWithAttributeSupport(null, true, true, true, true));\n```\n\nSerializing and Deserializing works the same.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstefh%2Fsystem.text.json.enumextensions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstefh%2Fsystem.text.json.enumextensions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstefh%2Fsystem.text.json.enumextensions/lists"}