{"id":22101139,"url":"https://github.com/rmja/polyjson","last_synced_at":"2025-07-25T00:31:13.030Z","repository":{"id":43285845,"uuid":"439311660","full_name":"rmja/PolyJson","owner":"rmja","description":"Attribute based, polymorphic support for System.Text.Json.","archived":false,"fork":false,"pushed_at":"2023-12-12T05:27:46.000Z","size":37,"stargazers_count":12,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-04-26T22:42:17.275Z","etag":null,"topics":["json","polymorphism","system-text-json"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rmja.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-12-17T11:35:36.000Z","updated_at":"2024-03-28T00:38:58.000Z","dependencies_parsed_at":"2023-01-23T00:30:14.220Z","dependency_job_id":null,"html_url":"https://github.com/rmja/PolyJson","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rmja%2FPolyJson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rmja%2FPolyJson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rmja%2FPolyJson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rmja%2FPolyJson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rmja","download_url":"https://codeload.github.com/rmja/PolyJson/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227489804,"owners_count":17780628,"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":["json","polymorphism","system-text-json"],"created_at":"2024-12-01T05:23:43.234Z","updated_at":"2024-12-01T05:23:43.879Z","avatar_url":"https://github.com/rmja.png","language":"C#","readme":"# PolyJson\r\n\r\nAttribute based, polymorphic support for System.Text.Json (and optionally Newtonsoft.Json). It supports both serialization and deserialization and is reasonably fast.\r\n\r\n## Nuget Packages\r\n\r\n| Package name                      | Description\t\t\t\t    | Badge |\r\n|-----------------------------------|-------------------------------|-------|\r\n| `PolyJson`                 | Basic types and System.Text.Json support\t\t\t\t    | [![PolyJson](https://img.shields.io/nuget/vpre/PolyJson.svg)](https://www.nuget.org/packages/PolyJson) |\r\n| `PolyJson.NewtonsoftJson`              | Optional Newtonsoft.Json support\t\t\t\t    | [![PolyJson.NewtonsoftJson](https://img.shields.io/nuget/vpre/PolyJson.NewtonsoftJson.svg)](https://www.nuget.org/packages/PolyJson.NewtonsoftJson) |\r\n\r\n## Usage\r\n\r\nDecorate the base class with the `PolyJsonConverter` attribute and register the subtypes:\r\n\r\n```C#\r\n[PolyJsonConverter(\"_t\")]\r\n//[Newtonsoft.Json.JsonConverter(typeof(PolyJsonNewtonsoftJsonConverter))] // Optional\r\n[PolyJsonConverter.SubType(typeof(Dog), \"dog\")]\r\n[PolyJsonConverter.SubType(typeof(Cat), \"cat\")]\r\npublic abstract class Animal\r\n{\r\n    [JsonPropertyName(\"_t\")]\r\n    //[Newtonsoft.Json.JsonProperty(\"_t\")] // Optional\r\n    public string Discriminator =\u003e DiscriminatorValue.Get(GetType());\r\n    public int Id { get; set; }\r\n}\r\n```\r\n\r\nThe `PolyJsonConverter` specifies the discriminator field, in this case `_t`. And all possible sub types are registered with their discriminator value.\r\nThe `Newtonsoft.Json` support is optional, but uses the same configured subtypes as that configured for `System.Text.Json`.\r\nA sub type does not have any attributes and can for example be:\r\n\r\n```C#\r\npublic class Dog : Animal\r\n{\r\n    public bool CanBark { get; set; }\r\n}\r\n```\r\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frmja%2Fpolyjson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frmja%2Fpolyjson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frmja%2Fpolyjson/lists"}