dotnet-json-polymorphic

Apply JsonPolymorphic and JsonDerivedType attributes for polymorphic JSON serialization in .NET.

6|2|Updated Aug 14, 2025
One-click install
npx skills add https://github.com/Im5tu/claude --skill dotnet-json-polymorphic
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dotnet-json-polymorphic
Source: https://github.com/Im5tu/claude/tree/main/skills/dotnet-json-polymorphic
Command: npx skills add https://github.com/Im5tu/claude --skill dotnet-json-polymorphic

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill enables type-safe polymorphic JSON serialization in .NET applications.

Core Features & Use Cases

  • Polymorphic serialization for base/derived types using System.Text.Json.
  • Automatic TypeDiscriminator via JsonPolymorphic and JsonDerivedType attributes.
  • Use Case: serialize a tree of shapes (Shape -> Circle, Rectangle) with correct derived types.

Quick Start

Use the dotnet-json-polymorphic skill to apply JsonPolymorphic attributes to a base type and its derived types in a .NET project.

Frequently Asked Questions about dotnet-json-polymorphic

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I serialize inheritance hierarchies with System.Text.Json in .NET?

To serialize inheritance hierarchies with System.Text.Json, apply JsonPolymorphic and JsonDerivedType attributes to base types. This enables type-safe polymorphic JSON serialization and automatic TypeDiscriminator generation for derived classes.

What is polymorphic JSON serialization and when do I need TypeDiscriminators?

Polymorphic JSON serialization preserves derived type information when serializing base types. You need TypeDiscriminators when deserializing inheritance hierarchies, allowing the serializer to identify and instantiate the correct derived types automatically.

Does polymorphic JSON serialization in .NET support AOT-compatible source generation?

Yes, polymorphic JSON serialization supports AOT-compatible source generation. Applying JsonPolymorphic and JsonDerivedType attributes prepares types for source generation, ensuring type-safe serialization works in ahead-of-time compilation environments.

What .NET version is required to use JsonPolymorphic attributes?

Using JsonPolymorphic attributes requires .NET 7 or higher. This version introduced native support for type-safe polymorphic JSON serialization within System.Text.Json, enabling automatic discriminators for inheritance hierarchies.

What's the best way to configure System.Text.Json for derived types?

The best way to configure System.Text.Json for derived types is applying JsonPolymorphic to the base class and JsonDerivedType for each subclass. This approach ensures type-safe polymorphic serialization and proper automatic TypeDiscriminator handling.