Skip to content

System.Text.Json serialization in Orleans

Use the System.Text.Json integration to serialize and copy selected types in grain calls using your JSON contracts and converters.

Terminal window
dotnet add package Microsoft.Orleans.Serialization.SystemTextJson

Register AddJsonSerializer through the ISiloBuilder services. The following example selects types whose namespace starts with Example.Namespace:

siloBuilder.Services.AddSerializer(serializerBuilder =>
{
serializerBuilder.AddJsonSerializer(
isSupported: type => type.Namespace?.StartsWith("Example.Namespace", StringComparison.Ordinal) is true);
});

The isSupported delegate selects types for both serialization and deep copying. Pass jsonSerializerOptions to configure JsonSerializerOptions, including converters and polymorphism settings for your contracts.

Apply matching registrations and JSON options on every silo and client that exchanges these types. For types marked with GenerateSerializerAttribute, Orleans prefers the generated serializer.

Orleans wraps each delegated JSON payload with its wire metadata, including the runtime type. Configure type-name authorization for the application types you trust, and follow the System.Text.Json documentation for JSON contract behavior.

For persistence configuration, see Grain storage serializers.