Fast.Serialization.System.Text.Json
Public members, parameters, returns, and exceptions
Targets: net8.0;net9.0;net10.0.
Contract and constraints
System.Text.Json integration in the Fast.Serialization namespace. AddSerialization() creates options for JsonContext.SerializerOptions and applies its callback there. MVC receives the default configuration separately: apply application overrides again with AddControllers().AddJsonOptions(...). Minimal API HTTP JSON options are also separate. Defaults include yyyy-MM-dd HH:mm:ss dates, long values written as strings, AllowReadingFromString, IgnoreCycles, trailing commas, skipped comments and case-insensitive property names. Relaxed JSON escaping does not make output safe for embedding directly in HTML. ToObject removes before parsing and rejects null input. JSON null can yield a null reference despite the current annotations. DeepCopy and dictionary conversion round-trip through JSON and preserve only serializable data. Choose one Fast.Serialization implementation per application.
Installation and examples
Install the package
dotnet add package Fast.Serialization.System.Text.JsonExample 1
using Fast.Serialization;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Builder;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddSerialization();
builder.Services.AddControllers();
var app = builder.Build();
app.MapControllers();
app.Run();Example 2
using Fast.Serialization;
public sealed class OrderSnapshot
{
public long Id { get; set; }
public string Title { get; set; } = "";
}
public sealed class SnapshotCodec
{
public string Serialize(OrderSnapshot value) => value.ToJsonString();
public OrderSnapshot Deserialize(string json) => json.ToObject<OrderSnapshot>();
public OrderSnapshot Copy(OrderSnapshot value) => value.DeepCopy();
public OrderSnapshot FromFields(IDictionary<string, object> fields) =>
fields.ToObject<OrderSnapshot>();
}Web-host examples belong in a consumer project using Microsoft.NET.Sdk.Web and a supported .NET target. IaaS examples can be used in an ordinary class library. Registration precedes builder.Build(); configure middleware and endpoints before app.Run(). Samples retain their original code and comments. No host, external service, database operation or client generator was run, and these snippets have not been compiled in this update.
Source reference
Decimal precision
Default decimal/nullable-decimal output keeps the decimal value without conversion through double. Explicit Places still applies the existing Math.Round policy; null remains null. JavaScript number precision is a separate consumer constraint and may require a suitable high-precision representation.
