AgentStack
Browse Sign in
Browse Why AgentStack Sell Docs
Sign in
SKILL verified MIT Self-run

Dotnet Json Polymorphic

skill-im5tu-claude-dotnet-json-polymorphic · by Im5tu

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.

No reviews yet
0 installs
31 views
0.0% view→install

Install

$ agentstack add skill-im5tu-claude-dotnet-json-polymorphic

✓ scanned · ✓ verified, works with Claude Code, Cursor, and more.

Security review

✓ Passed

No issues found. Passed automated security review. · v0.1.0 How review works →

  • Prompt-injection patterns
  • Secret / credential exfiltration
  • Dangerous shell & filesystem operations
  • Untrusted network calls
  • Known-malicious package signatures

What it can access

  • Network access No
  • Filesystem access No
  • Shell / process execution No
  • Environment & secrets No
  • Dynamic code execution No

From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.

View the full security report →

Verified badge

Passed review? Show it. Paste this badge into your README, it links to the public security report.

AgentStack Verified badge Links to your public security report.
[![AgentStack Verified](https://agentstack.voostack.com/badges/verified.svg)](https://agentstack.voostack.com/security/report/skill-im5tu-claude-dotnet-json-polymorphic)

Reliability & compatibility

Security review passed
0 installs to date
no reviews yet
5mo ago

Declared compatibility

Claude CodeClaude Desktop

Compatibility is declared by the source manifest. End-to-end runtime verification is coming, see below.

Preview Execution monitoring

We're building live execution health for every listing: tool-call success rate, median latency, uptime, and last-checked timestamps, measured, not self-reported. It isn't live yet, so we don't show numbers we can't stand behind.

How agent discovery & health will work →
Are you the author of Dotnet Json Polymorphic? Claim this listing to set pricing, connect Stripe payouts, and keep 70% of every sale.
Sign up to claim

About

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 modern attributes

Requirements

  • .NET 7 or higher

Steps

  1. Ask scope:
  • Ask user: "Apply to entire solution or specific project?"
  • If specific project, ask which project
  1. Search for existing [JsonPolymorphic] attributes:
  • Detect existing project conventions
  • Note any TypeDiscriminatorPropertyName values found
  1. Extract discriminator conventions:
  • Search for TypeDiscriminatorPropertyName in existing attributes
  • Record all unique discriminator property names found
  1. 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
  1. Ask about discriminator property name:
  • If existing discriminators found, show them to user
  • Ask: "What discriminator property name? (Default: $type, Found: [list existing])"
  1. Check for consistency:
  • If multiple different discriminators found in codebase
  • Ask: "Found multiple discriminators: [list]. Standardize to single value?"
  1. 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")
  1. Add using directive:
  • Ensure using System.Text.Json.Serialization; is present
  1. Verify with build:

``bash dotnet build ``

  1. Report results:
  • List all base types configured
  • List all derived type mappings added
  • Confirm build status

Example Conversion

Before:

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:

[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:

{
  "$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(emailNotification))
  • Discriminator values: String discriminators are recommended over integers for readability and forward compatibility
  • Nested hierarchies: Each level in the hierarchy needs its own [JsonPolymorphic] attribute if it has derived types
  • Interface support: Interfaces can also use [JsonPolymorphic] when they define the contract for serialization

Documentation

Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

Install and usage instructions live in the source repository linked above.

Reviews

No reviews yet, be the first.

Versions

  • v0.1.0 Imported from the upstream source.