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.
Install the serializer package
Section titled “Install the serializer package”dotnet add package Microsoft.Orleans.Serialization.SystemTextJsonConfigure System.Text.Json
Section titled “Configure System.Text.Json”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.
Type authorization and contracts
Section titled “Type authorization and contracts”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.
