Install
$ agentstack add skill-im5tu-claude-dotnet-json-polymorphic ✓ scanned · ✓ verified, works with Claude Code, Cursor, and more.
Security review
✓ PassedNo 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.
Verified badge
Passed review? Show it. Paste this badge into your README, it links to the public security report.
Reliability & compatibility
Declared compatibility
Compatibility is declared by the source manifest. End-to-end runtime verification is coming, see below.
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 →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
TypeNameHandlingwith modern attributes
Requirements
- .NET 7 or higher
Steps
- Ask scope:
- Ask user: "Apply to entire solution or specific project?"
- If specific project, ask which project
- Search for existing
[JsonPolymorphic]attributes:
- Detect existing project conventions
- Note any
TypeDiscriminatorPropertyNamevalues found
- Extract discriminator conventions:
- Search for
TypeDiscriminatorPropertyNamein existing attributes - Record all unique discriminator property names found
- 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
- Ask about discriminator property name:
- If existing discriminators found, show them to user
- Ask: "What discriminator property name? (Default:
$type, Found: [list existing])"
- Check for consistency:
- If multiple different discriminators found in codebase
- Ask: "Found multiple discriminators: [list]. Standardize to single value?"
- 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")
- Add using directive:
- Ensure
using System.Text.Json.Serialization;is present
- Verify with build:
``bash dotnet build ``
- 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.
- Author: Im5tu
- Source: Im5tu/claude
- License: MIT
- Homepage: https://codewithstu.tv
Install and usage instructions live in the source repository linked above.
Reviews
No reviews yet, be the first.
Write a review
Versions
- v0.1.0 Imported from the upstream source.