{"id":13629302,"url":"https://github.com/surgicalcoder/JsonPolymorphicGenerator","last_synced_at":"2025-04-17T08:34:39.350Z","repository":{"id":162541270,"uuid":"637037997","full_name":"surgicalcoder/JsonPolymorphicGenerator","owner":"surgicalcoder","description":"c# / .net Source Code Generator for System.Text.Json JsonDerivedType attributes on polymorphic classes","archived":false,"fork":false,"pushed_at":"2023-07-16T17:11:13.000Z","size":20,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-05-12T12:41:21.364Z","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/surgicalcoder.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"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}},"created_at":"2023-05-06T10:08:22.000Z","updated_at":"2023-11-21T15:23:15.000Z","dependencies_parsed_at":null,"dependency_job_id":"f46eb8b0-3c7e-43cd-922a-f4f877ab9ef8","html_url":"https://github.com/surgicalcoder/JsonPolymorphicGenerator","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/surgicalcoder%2FJsonPolymorphicGenerator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/surgicalcoder%2FJsonPolymorphicGenerator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/surgicalcoder%2FJsonPolymorphicGenerator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/surgicalcoder%2FJsonPolymorphicGenerator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/surgicalcoder","download_url":"https://codeload.github.com/surgicalcoder/JsonPolymorphicGenerator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249326186,"owners_count":21251735,"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-08-01T22:01:06.943Z","updated_at":"2025-04-17T08:34:39.113Z","avatar_url":"https://github.com/surgicalcoder.png","language":"C#","readme":"# JsonPolymorphicGenerator\nc# / .net Source Code Generator for System.Text.Json JsonDerivedType attributes on polymorphic classes\n\n## Usage\n\nFor this, your base classes need the `partial` and `abstract` key words, and be decorated with `JsonPolymorphic`, and there need to be derived types in that same assembly for this to work.\n\nAn example of this is:\n\n```\n[JsonPolymorphic]\npublic abstract partial class BaseClass\n{\n    public string Property1 { get; set; }\n}\n```\n\nThis will then generate a partial class, that is decorated with the `JsonDerivedType` attribute, and use the class name as the discriminator.\n\n```\n[JsonDerivedType(typeof(GoLive.JsonPolymorphicGenerator.Playground.InheritedClass1), \"InheritedClass1\")]\n[JsonDerivedType(typeof(GoLive.JsonPolymorphicGenerator.Playground.InheritedClass2), \"InheritedClass2\")]\npublic partial class BaseClass\n{\n}\n```\n\nYou can now transform the text of the attributes that gets spat out! You have a number of options, that gets added to an `.editorconfig`, such as:\n\n```\nroot = true\n\n[*.cs]\njsonpolymorphicgenerator.text_preappend = JSON_\njsonpolymorphicgenerator.text_transform = return classname.GetHashCode().ToString()\njsonpolymorphicgenerator.text_postappend = _A\n```\n\nFor the `jsonpolymorphicgenerator.text_transform` option, you have to provide valid c# code, that returns a string - there are 2 input variables - `classname` and `namespacename`","funding_links":[],"categories":["Content","Source Generators"],"sub_categories":["68. [JsonPolymorphicGenerator](https://ignatandrei.github.io/RSCG_Examples/v2/docs/JsonPolymorphicGenerator) , in the [Serializer](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#serializer) category","Serialization"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsurgicalcoder%2FJsonPolymorphicGenerator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsurgicalcoder%2FJsonPolymorphicGenerator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsurgicalcoder%2FJsonPolymorphicGenerator/lists"}