serialization
Agent skill fromAaronontheweb/dotnet-skills
Choose the right serialization format for .NET applications. Prefer schema-based formats (Protobuf, MessagePack) over reflection-based (Newtonsoft.Json). Use System.Text.Json with AOT source generators for JSON scenarios.
How to install serialization
install serialization
# install the dotnet-skills pack with the skills CLI
npx skills add Aaronontheweb/dotnet-skills# or add only this skill to Claude Code: copy the folder
skills/serialization/
# into
~/.claude/skills/serialization/ (all projects)
.claude/skills/serialization/ (one project)
1# Serialization in .NET23## When to Use This Skill45Use this skill when:6- Choosing a serialization format for APIs, messaging, or persistence7- Migrating from Newtonsoft.Json to System.Text.Json8- Implementing AOT-compatible serialization9- Designing wire formats for distributed systems10- Optimizing serialization performance1112---1314## Schema-Based vs Reflection-Based1516| Aspect | Schema-Based | Reflection-Based |17|--------|--------------|------------------|18| **Examples** | Protobuf, MessagePack, System.Text.Json (source gen) | Newtonsoft.Json, BinaryFormatter |19| **Type info in payload** | No (external schema) | Yes (type names embedded) |20| **Versioning** | Explicit field numbers/names | Implicit (type structure) |21| **Performance** | Fast (no reflection) | Slower (runtime reflection) |22| **AOT compatible** | Yes | No |23| **Wire compatibility** | Excellent | Poor |2425**Recommendation**: Use schema-based serialization for anything that crosses process boundaries.2627---2829## Format Recommendations3031| Use Case | Recommended Format | Why |32|----------|-------------------|-----|33| **REST APIs** | System.Text.Json (source gen) | Standard, AOT-compatible |34| **gRPC** | Protocol Buffers | Native format, excellent versioning |35| **Actor messaging** | MessagePack or Protobuf | Compact, fast, version-safe |36| **Event sourcing** | Protobuf or MessagePack | Must handle old events forever |37| **Caching** | MessagePack | Compact, fast |38…
Excerpt shown under the repository's MIT license.
