원클릭으로
dotnet-source-gen-json
Configures System.Text.Json source generation for AOT-compatible JSON serialization
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
Configures System.Text.Json source generation for AOT-compatible JSON serialization
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
Analyzes and configures a .NET project or solution for Native AOT compatibility. Orchestrates source generator skills and applies AOT settings.
Converts a .NET solution to use Central Package Management (CPM). Use when the user wants to centralize, consolidate, or unify NuGet package versions across projects.
Enables tab autocomplete for the dotnet CLI. Use when the user wants to set up shell completion for dotnet commands.
Enables the Microsoft Testing Platform runner in global.json. Use when the user wants to enable or migrate to the new .NET testing platform.
Configures polymorphic JSON serialization with [JsonPolymorphic] and [JsonDerivedType] attributes
Converts logging to use the LoggerMessage source generator for high-performance, AOT-compatible logging. Use when the user wants to optimize logging or organize log messages.
| name | dotnet-source-gen-json |
| description | Configures System.Text.Json source generation for AOT-compatible JSON serialization |
| license | MIT |
| metadata | {"author":"Im5tu","version":"1.0","repositoryUrl":"https://github.com/im5tu/dotnet-skills"} |
| allowed-tools | Bash(dotnet:*) Read Glob Grep AskUserQuestion |
Configure System.Text.Json source generation for AOT-compatible, reflection-free JSON serialization with compile-time type metadata.
Invoke polymorphic skill first:
dotnet-json-polymorphic skill to ensure polymorphic types are configured[JsonDerivedType] attributes are in place before generating contextAsk scope:
Scan for API endpoint types:
MapGet, MapPost, MapPut, MapDelete, MapPatchScan for controller types:
[HttpGet], [HttpPost], [HttpPut], [HttpDelete], [HttpPatch]Find direct serialization calls:
JsonSerializer.Serialize and JsonSerializer.Deserialize callsCheck for existing JsonSerializerContext:
JsonSerializerContext[JsonSerializable] types to avoid duplicatesAsk about enum serialization:
Ask about property naming:
Ask about null value handling:
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNullCreate JsonSerializerContext:
{ProjectName}JsonContext.cs in project root (same level as Program.cs){ProjectName}JsonContextAdd source generation options:
[JsonSourceGenerationOptions(
PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)]
[JsonSerializable(typeof(WeatherForecast))]
[JsonSerializable(typeof(List<WeatherForecast>))]
public partial class MyApiJsonContext : JsonSerializerContext
{
}
Include collection types:
T, also add [JsonSerializable(typeof(List<T>))][JsonSerializable(typeof(T[]))] if arrays are usedConfigure ASP.NET Core:
builder.Services.ConfigureHttpJsonOptions(options =>
{
options.SerializerOptions.TypeInfoResolver = MyApiJsonContext.Default;
});
Verify with build:
dotnet build
Report results:
using System.Text.Json;
using System.Text.Json.Serialization;
namespace MyApi;
[JsonSourceGenerationOptions(
PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
Converters = [typeof(JsonStringEnumConverter<Status>)])]
[JsonSerializable(typeof(WeatherForecast))]
[JsonSerializable(typeof(List<WeatherForecast>))]
[JsonSerializable(typeof(CreateOrderRequest))]
[JsonSerializable(typeof(OrderResponse))]
[JsonSerializable(typeof(List<OrderResponse>))]
[JsonSerializable(typeof(ErrorResponse))]
public partial class MyApiJsonContext : JsonSerializerContext
{
}
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();
For full AOT compatibility, add to the Directory.Build.props file (preferred), or project file:
<PropertyGroup>
<JsonSerializerIsReflectionEnabledByDefault>false</JsonSerializerIsReflectionEnabledByDefault>
</PropertyGroup>
This ensures compile-time errors if any type is missing from the context.
{ProjectName}JsonContext for consistencyList<T> and array types if used in APIsdotnet-json-polymorphic first; polymorphic types use metadata-based generation onlyJsonStringEnumConverter<TEnum> requires .NET 8+ for AOT supportJsonTypeInfoResolver.Combine() to merge them