dotnet-json-polymorphic
Configures polymorphic JSON serialization with [JsonPolymorphic] and [JsonDerivedType] attributes.
Skill by Im5tu
Install
Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.
npx agentmarket install skill/im5tu-dotnet-json-polymorphic
Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.
Get the weekly diff
The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.
About
Reviews
Write a reviewNo reviews yet. Installed it? Reviews come from verified installers only. How reviews work
Permissions
What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.
- Tools
- No tools found
- Secrets
- None asked for
- Install scripts
- None found
Network hosts it talks to 1
codeload.github.com· found in install command
Files it touches
~/.claude/skills/dotnet-json-polymorphic
Tools it pre-approves 7
From allowed-tools in SKILL.md: the agent may use these without asking you each time.
Bash(dotnet:*),Read,Edit,Write,Glob,Grep,AskUserQuestion
What's inside
- Skill name
dotnet-json-polymorphic- Description
- Configures polymorphic JSON serialization with [JsonPolymorphic] and [JsonDerivedType] attributes. Also use when the user mentions "polymorphic JSON," "JsonDerivedType," "JSON inheritance," "type discriminator," "serialize derived types," or "JSON polymorphism." For full JSON source generation, see dotnet-source-gen-json.
- License
- MIT
- Allowed tools
- Bash(dotnet:*),, Read,, Edit,, Write,, Glob,, Grep,, AskUserQuestion
- Metadata
- author: Im5tu · version: 1.0 · repositoryUrl: https://github.com/im5tu/dotnet-skills
- Instructions
- 127 lines in SKILL.md · view on GitHub
Before installing
- Pre-approves some shell commands
Files (1)
- SKILL.md
SKILL.md (first lines)
Configure polymorphic JSON serialization using `[JsonPolymorphic]` and `[JsonDerivedType]` attributes for type-safe inheritance hierarchies.
## When to Use
- Serializing inheritance hierarchies with System.Text.Json
- Adding type discriminators for polymorphic deserialization
- Preparing polymorphic types for AOT-compatible JSON source generation
- Replacing Newtonsoft.Json `TypeNameHandling` with `[JsonPolymorphic]`/`[JsonDerivedType]`
## Requirements
- .NET 7 or higher
## Steps
1. **Ask scope**:
- Ask user: "Apply to entire solution or specific project?"
- If specific project, ask which project
2. **Search for existing `[JsonPolymorphic]` attributes**:
- Detect existing project conventions
- Note any `TypeDiscriminatorPropertyName` values found
3. **Extract discriminator conventions**:
- Search for `TypeDiscriminatorPropertyName` in existing attributes
- Record all unique discriminator property names found
4. **Find polymorphic candidates**:
- Search for abstract classes with derived types
- Search for interfaces with implementing classes used in serialization
- Look for classes with virtual members that are inherited
5. **Ask about discriminator property name**:
- If existing discriminators found, show them to user
- Ask: "What discriminator property name? (Default: `$type`, Found: [list existing])"
6. **Check for consistency**:
- If multiple different discriminators found in codebase
- Ask: "Found multiple discriminators: [list]. Standardize to single value?"
7. **Apply attributes to base types**:
```csharp
[JsonPolymorphic(TypeDiscriminatorPropertyName = "$type")]
[JsonDerivedType(typeof(DerivedA), typeDiscriminator: "DerivedA")]
[JsonDerivedType(typeof(DerivedB), typeDiscriminator: "DerivedB")]
public abstract class BaseClass
{
}
```
- Use full type name as discriminator value (e.g., `"WeatherForecastWithCity"`)
8. **Add using directive**:
- Ensure `using System.Text.Json.Serialization;` is present
9. **Verify with build**:
```bash
dotnet build
```
10. **Report results**:
- List all base types configured
- List all derived type mappings added
- Confirm build status
## Example Conversion
**Before:**
```csharp
public abstract class Notification
{
public string Message { get; set; }
}
public class EmailNotification : Notification
{
public string EmailAddress { get; set; }
}
public class SmsNotification : Notification
{
public string PhoneNumber { get; set; }
}
```
**After:**
```csharp
[JsonPolymorphic(TypeDiscriminatorPropertyName = "$type")]
[JsonDerivedType(typeof(EmailNotification), typeDiscriminator: "EmailNotification")]
[JsonDerivedType(typeof(SmsNotification), typeDiscriminator: "SmsNotification")]
public abstract class Notification
{
public string Message { get; set; }
}
public class EmailNotification : Notification
{
public string EmailAddress { get; set; }
}
public class SmsNotification : Notification
{
public string PhoneNumber { get; set; }
}
```
**JSON Output:**
```json
{
"$type": "EmailNotification",
"message": "Hello",
"emailAddress": "user@example.com"
}
```
## Notes
- **AOT Compatibility**: Metadata-based source generation is supported; fast-path source generation is NOT supported for polymorphic types
- **Serialization requirement**: Must serialize using the base type for polymorphism to work (e.g., `JsonSerializer.Serialize<Notification>(emailNotification)`)
- **Discriminator values**: String discriminators are recommended over integers for readability and forward compatibilityFrom Im5tu/claude, MIT.
More from Im5tu/claude
- 0.587score
website-seo
Im5tu
When the user wants SEO strategy, audits, technical SEO, schema markup, content architecture, or search visibility optimization.
SkillBFreshness: B★ 6Claude Code - 0.587score
website-design
Im5tu
When the user wants to design and build a premium multi-page website for any business type.
SkillBFreshness: B★ 6Claude Code - 0.582score
dotnet-centralise-packages
Im5tu
Converts a .NET solution to use Central Package Management (CPM).
SkillBFreshness: B★ 6Claude Code +9 - 0.582score
dotnet-source-gen-json
Im5tu
Configures System.Text.Json source generation for AOT-compatible JSON serialization.
SkillBFreshness: B★ 6Claude Code +9 - 0.582score
dotnet-source-gen-logging
Im5tu
Converts logging to use the LoggerMessage source generator for high-performance, AOT-compatible logging.
SkillBFreshness: B★ 6Claude Code +9 - 0.582score
dotnet-source-gen-options-validation
Im5tu
Converts options validation to use the compile-time source generator for AOT-compatible, reflection-free validation.
SkillBFreshness: B★ 6Claude Code +9 - 0.582score
dotnet-source-gen-regex
Im5tu
Converts Regex instances to use the compile-time source generator.
SkillBFreshness: B★ 6Claude Code +9 - 0.582score
dotnet-update-packages
Im5tu
Lists and updates outdated NuGet packages in .NET projects.
SkillBFreshness: B★ 6Claude Code +9 - 0.582score
dotnet-enable-testing-platform
Im5tu
Enables the Microsoft Testing Platform runner in global.json.
SkillBFreshness: B★ 6Claude Code +9 - 0.582score
dotnet-aot-analysis
Im5tu
Analyzes and configures a .NET project or solution for Native AOT compatibility.
SkillBFreshness: B★ 6Claude Code +9 - 0.548score
plan-feature
Im5tu
Interview user in-depth to create a detailed spec.
SkillBFreshness: B★ 6Claude Code +9 - 0.463score
reprompt
Im5tu
Formats input into Goal, Constraints, Format, Failure structure.
SkillDFreshness: D★ 6Claude Code +9
Signals
- Stars
- 6
- Forks
- 3
- Open issues
- 0
- Last commit (this folder)
- Aug 21, 2026 (2 months ago)
From GitHub (fetched Oct 24, 2026).
Details
- Version
- 1.0
- License
- MIT
- Repository
- github.com/Im5tu/claude
- Website
- codewithstu.tv
- First seen
- Oct 24, 2026
- Last checked
- Oct 24, 2026
- Source
- GitHubgithub-graphql
More from Im5tu
- 0.587score
website-seo
Im5tu
When the user wants SEO strategy, audits, technical SEO, schema markup, content architecture, or search visibility optimization.
SkillBFreshness: B★ 6Claude Code - 0.587score
website-design
Im5tu
When the user wants to design and build a premium multi-page website for any business type.
SkillBFreshness: B★ 6Claude Code - 0.582score
dotnet-centralise-packages
Im5tu
Converts a .NET solution to use Central Package Management (CPM).
SkillBFreshness: B★ 6Claude Code +9 - 0.582score
dotnet-source-gen-json
Im5tu
Configures System.Text.Json source generation for AOT-compatible JSON serialization.
SkillBFreshness: B★ 6Claude Code +9 - 0.582score
dotnet-source-gen-logging
Im5tu
Converts logging to use the LoggerMessage source generator for high-performance, AOT-compatible logging.
SkillBFreshness: B★ 6Claude Code +9 - 0.582score
dotnet-source-gen-options-validation
Im5tu
Converts options validation to use the compile-time source generator for AOT-compatible, reflection-free validation.
SkillBFreshness: B★ 6Claude Code +9
Cite this page
dotnet-json-polymorphic skill. Agent Mart. https://agentmart.dev/skills/im5tu-dotnet-json-polymorphic (last updated 2026-10-24)