serialization

Guide .NET developers in selecting schema-based serialization formats like Protobuf and MessagePack.

Updated Dec 4, 2022
One-click install
npx skills add https://github.com/devingoble/CloudOStat --skill serialization-devingoble
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: serialization
Source: https://github.com/devingoble/CloudOStat/tree/main/.github/skills/serialization
Command: npx skills add https://github.com/devingoble/CloudOStat --skill serialization-devingoble

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill helps developers select the most efficient and appropriate serialization format for their .NET applications, moving away from less performant or insecure options towards modern, schema-based solutions.

Core Features & Use Cases

  • Format Selection Guidance: Provides recommendations for various use cases like REST APIs, gRPC, messaging, and persistence.
  • Schema-Based vs. Reflection-Based: Explains the trade-offs and recommends schema-based formats (Protobuf, MessagePack, System.Text.Json with source generators) over reflection-based ones (Newtonsoft.Json).
  • Migration Assistance: Offers patterns and common issues when migrating from Newtonsoft.Json to System.Text.Json.
  • Performance Insights: Compares the performance and size characteristics of different serialization formats.

Quick Start

Use the serialization skill to recommend the best format for a new gRPC service.

Frequently Asked Questions about serialization

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

FAQPage Schema
What's the best .NET serialization format for high-performance messaging?

For high-performance .NET serialization, schema-based formats like Protobuf and MessagePack are recommended over reflection-based options, offering superior speed and smaller payload sizes for messaging scenarios.

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

Migrating from Newtonsoft.Json to System.Text.Json involves using source generators for AOT compatibility and performance, addressing common serialization differences and applying specific migration patterns to update your API handlers.

Does .NET serialization with System.TextJson source generators work for AOT?

Yes, System.Text.Json source generators provide AOT-compatible .NET serialization by generating serialization code at compile time, eliminating runtime reflection dependencies and improving application startup performance.

Protobuf vs MessagePack: which schema-based serialization should I use?

Protobuf is ideal for strict API contracts and gRPC, while MessagePack offers compact binary serialization for general messaging; both are recommended over reflection-based formats to maximize .NET serialization performance.

When do I need schema-based serialization instead of reflection-based JSON?

You need schema-based serialization for REST APIs, gRPC, messaging, and persistence scenarios where performance and payload size matter, moving away from reflection-based JSON to formats like Protobuf and MessagePack.