Developer knowledge network · moderated exchange

UnreliableCode 커뮤니티

개발자 연구, 리버스 엔지니어링 및 코딩 커뮤니티

Knowledge index살다
4Categories
919Threads
2.8K게시물
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.