Install
$ agentstack add skill-im5tu-claude-dotnet-source-gen-json ✓ 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 System.Text.Json source generation for AOT-compatible, reflection-free JSON serialization with compile-time type metadata.
When to Use
- Preparing application for Native AOT compilation
- Eliminating reflection-based serialization overhead
- Improving startup performance by generating serialization code at compile time
- Ensuring JSON serialization errors surface at compile time
Requirements
- .NET 8 or higher for full options support
- .NET 6+ for basic source generation
Steps
- Invoke polymorphic skill first:
- Run
dotnet-json-polymorphicskill to ensure polymorphic types are configured - This ensures
[JsonDerivedType]attributes are in place before generating context
- Ask scope:
- Ask user: "Apply to entire solution or specific project?"
- Filter to ASP.NET Core projects (those with web SDK or API endpoints)
- Scan for API endpoint types:
- Search for Minimal API patterns:
MapGet,MapPost,MapPut,MapDelete,MapPatch - Extract request/response types from lambda parameters and return types
- Scan for controller types:
- Search for controller attributes:
[HttpGet],[HttpPost],[HttpPut],[HttpDelete],[HttpPatch] - Extract parameter types and return types from action methods
- Find direct serialization calls:
- Search for
JsonSerializer.SerializeandJsonSerializer.Deserializecalls - Extract type arguments from these calls
- Check for existing JsonSerializerContext:
- Search for classes inheriting from
JsonSerializerContext - Note existing
[JsonSerializable]types to avoid duplicates
- Ask about enum serialization:
- Ask user: "Enable enum-as-string converter? (Recommended: Yes)"
- Ask about property naming:
- Ask user: "Select property naming policy:"
- CamelCase (Recommended)
- SnakeCaseLower
- SnakeCaseUpper
- KebabCaseLower
- KebabCaseUpper
- None (preserve original casing)
- Ask about null value handling:
- Ask user: "Serialize null values? (Recommended: No)"
- No - Omit null properties from output (smaller payloads)
- Yes - Include null properties in output
- If No: Add
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
- Create JsonSerializerContext:
- File:
{ProjectName}JsonContext.csin project root (same level as Program.cs) - Class name:
{ProjectName}JsonContext
- Add source generation options:
``csharp [JsonSourceGenerationOptions( PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)] [JsonSerializable(typeof(WeatherForecast))] [JsonSerializable(typeof(List))] public partial class MyApiJsonContext : JsonSerializerContext { } ``
- Include collection types:
- For each type
T, also add[JsonSerializable(typeof(List))] - Add
[JsonSerializable(typeof(T[]))]if arrays are used
- Configure ASP.NET Core:
- Add to Program.cs:
``csharp builder.Services.ConfigureHttpJsonOptions(options => { options.SerializerOptions.TypeInfoResolver = MyApiJsonContext.Default; }); ``
- Verify with build:
``bash dotnet build ``
- Report results:
- List the JsonSerializerContext file created
- List all types added to [JsonSerializable]
- Confirm ASP.NET Core integration added
- Confirm build status
Example Context
using System.Text.Json;
using System.Text.Json.Serialization;
namespace MyApi;
[JsonSourceGenerationOptions(
PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
Converters = [typeof(JsonStringEnumConverter)])]
[JsonSerializable(typeof(WeatherForecast))]
[JsonSerializable(typeof(List))]
[JsonSerializable(typeof(CreateOrderRequest))]
[JsonSerializable(typeof(OrderResponse))]
[JsonSerializable(typeof(List))]
[JsonSerializable(typeof(ErrorResponse))]
public partial class MyApiJsonContext : JsonSerializerContext
{
}
ASP.NET Core Integration
Program.cs:
var builder = WebApplication.CreateBuilder(args);
builder.Services.ConfigureHttpJsonOptions(options =>
{
options.SerializerOptions.TypeInfoResolver = MyApiJsonContext.Default;
});
var app = builder.Build();
app.MapGet("/weather", () => new WeatherForecast("Seattle", 72));
app.MapPost("/orders", (CreateOrderRequest request) => Results.Ok(new OrderResponse()));
app.Run();
AOT Configuration
For full AOT compatibility, add to the Directory.Build.props file (preferred), or project file:
false
This ensures compile-time errors if any type is missing from the context.
Notes
- Context naming: Use
{ProjectName}JsonContextfor consistency - File location: Place in project root alongside Program.cs
- Collection types: Always include
Listand array types if used in APIs - Polymorphic types: Run
dotnet-json-polymorphicfirst; polymorphic types use metadata-based generation only - Enum handling:
JsonStringEnumConverterrequires .NET 8+ for AOT support - Multiple contexts: Can have multiple contexts; use
JsonTypeInfoResolver.Combine()to merge them
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.