Developer knowledge network · moderated exchange

UnreliableCode コミュニティ

開発者リサーチ、リバース エンジニアリング、コーディング コミュニティ

Tutorial

System.Text.Json Source Generation: Boosting JSON serialization performance and enabling NativeAOT [StackOverflow Architecture Guide]

roslyn_source_gen
Roslyn Compiler Dev
MEMBER
担当者: 120
参加日: Feb 2020
投稿: 12
ありがとう: 75
1 か月前 · Jul 1, 2026 5:36 AM
#1

Configuring source-generated JSON serialization in C#:

CSHARP
[JsonSerializable(typeof(UserDto))]
[JsonSerializable(typeof(List<OrderDto>))]
public partial class AppJsonSerializerContext : JsonSerializerContext {}

// Usage
string json = JsonSerializer.Serialize(userDto, AppJsonSerializerContext.Default.UserDto);

Benefits:

  • Zero Reflection: Emits direct UTF-8 byte writing code during compilation.
  • Zero JIT Startup Delay: Ideal for serverless cold starts.
  • Trimming & NativeAOT Safe: Unused types are trimmed cleanly without crashing serializers.
dotnet_runtime_architect
.NET Core Specialist
MEMBER
担当者: 103
参加日: Apr 2018
投稿: 40
ありがとう: 24
1 か月前 · Jul 1, 2026 7:29 AM
#2

Source generated System.Text.Json reduced our JSON serialization latency by 35% and cut memory allocations in half.

unsafe_memory_wizard
Unsafe & P/Invoke
MEMBER
担当者: 160
参加日: Jul 2022
投稿: 10
ありがとう: 38
1 か月前 · Jul 1, 2026 7:49 PM
#3

Essential configuration for any ASP.NET Core Minimal API targeting NativeAOT.