Skip to main content
net10.0net8.0net9.0

ASP.NET Core MVC input and output formatters backed by Nerdbank.Json, enabling AOT-safe, source-generated JSON in MVC and minimal-hosting Web APIs with an explicitly supplied ITypeShapeProvider.

Published
Sep 25, 2026
25d ago
Total Downloads
146
146

Install

dotnet add package Nerdbank.Json.AspNetCoreMvcFormatter --version 0.1.1041-alpha
ProductVersions
.NET
net10.0net8.0net9.0

README

Nerdbank.Json.AspNetCoreMvcFormatter

ASP.NET Core MVC input and output formatters backed by Nerdbank.Json, enabling AOT-safe, source-generated JSON in MVC and minimal-hosting Web APIs.

Unlike the built-in System.Text.Json formatters, these formatters:

  • use an explicitly supplied, source-generated ITypeShapeProvider — no reflection and no runtime type discovery;
  • stream request and response bodies incrementally through Nerdbank.Json's PipeReader/PipeWriter APIs;
  • are trimming- and NativeAOT-safe.

Usage

using Microsoft.Extensions.DependencyInjection;
using Nerdbank.Json;
using PolyType;

var serializer = new JsonSerializer();

builder.Services
    .AddControllers()
    .AddNerdbankJsonFormatters(serializer, MyWitness.GeneratedTypeShapeProvider);

MyWitness is any type (often a witness) that lists your model types via [GenerateShape] / [GenerateShapeFor<T>]; its generated ITypeShapeProvider describes every type the formatters can read or write.

By default the Nerdbank.Json formatters are inserted before the built-in System.Text.Json formatters (so they win content negotiation for application/json and +json media types) but do not remove them. To fully take over JSON handling:

.AddNerdbankJsonFormatters(serializer, provider, o => o.ReplaceSystemTextJsonFormatters = true);

If the provider has no shape for a model type, the formatters throw a MissingTypeShapeException rather than silently binding null or falling through, so misconfiguration is obvious.

Changes from Previous Version

No structural changes between v0.1.1010-alpha and v0.1.1041-alpha.

Adoption Assessment

A verified publisher signal is available. Assess fit from the package's supported frameworks, license and dependency graph rather than popularity alone.

This version is marked prerelease. Validate its API and upgrade path before production use.Compatibility metadata lists 3 target frameworks; confirm the exact target used by your application.The published metadata declares 14 direct dependency entries across framework groups. Inspect the resolved dependency graph for your target framework.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.