serialization

Select .NET serialization formats for APIs, messaging, and persistence.

Updated Jan 29, 2024
One-click install
npx skills add https://github.com/riandeoliveira/aspnet-template --skill serialization-riandeoliveira
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: serialization
Source: https://github.com/riandeoliveira/aspnet-template/tree/main/.claude/skills/serialization
Command: npx skills add https://github.com/riandeoliveira/aspnet-template --skill serialization-riandeoliveira

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Serialization choices strongly impact performance, compatibility, versioning, and whether your .NET app can run well under Native AOT without reflection-heavy runtime costs.

Core Features & Use Cases

  • Schema-based vs reflection-based guidance: Choose wire formats like Protobuf and MessagePack over reflection-centric approaches like Newtonsoft.Json.
  • System.Text.Json for JSON with AOT source generation: Configure JsonSerializerContext and integrate it with ASP.NET Core HTTP JSON options.
  • Practical migration and versioning patterns: Move from Newtonsoft.Json to System.Text.Json with clear replacements for property naming, null handling, and polymorphism via discriminators.

Quick Start

Ask: "Help me choose a serialization format for an ASP.NET Core API and show how to configure System.Text.Json source generation for my DTOs, including how to migrate from Newtonsoft.Json safely."

Frequently Asked Questions about serialization

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
What's the best way to choose a .NET serialization format for APIs and messaging?

Choosing a .NET serialization format depends on your performance, versioning, and Native AOT compatibility needs. Schema-based formats like Protobuf and MessagePack are preferred for wire compatibility over reflection-centric approaches like Newtonsoft.Json.

How do I configure System.Text.Json source generation for ASP.NET Core DTOs?

To configure System.Text.Json source generation, you implement a JsonSerializerContext for your DTOs and integrate it with the ASP.NET Core HTTP JSON options. This enables AOT-friendly serialization without reflection-heavy runtime costs.

How do I migrate from Newtonsoft.Json to System.Text.Json safely?

To migrate from Newtonsoft.Json to System.Text.Json, you apply practical versioning patterns and use clear replacements for property naming, null handling, and polymorphism via discriminators to ensure forward compatibility.

Does .NET serialization work with Native AOT without using runtime reflection?

.NET serialization works with Native AOT by using System.Text.Json source generators instead of reflection. Configuring a JsonSerializerContext provides AOT-friendly serialization that avoids unsafe runtime costs.

When should I use schema-based serialization like Protobuf over JSON in .NET?

You should use schema-based serialization like Protobuf over JSON when you need strict wire compatibility and versioning. Configuring tolerant readers for forward compatibility is recommended to handle schema evolution safely.

What are the limitations of using BinaryFormatter for .NET serialization?

The limitation of using BinaryFormatter is that it is an unsafe practice due to embedding type names. You should avoid it and prefer schema-based serialization formats like Protobuf or MessagePack for secure wire contracts.