Skip to content

Newtonsoft.Json serialization in Orleans

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

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

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

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

The isSupported delegate selects types for both serialization and deep copying. Pass jsonSerializerSettings to configure JsonSerializerSettings, including converters and other contract settings.

Apply matching registrations and JSON settings 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 review serialization security when configuring JSON type handling.

For persistence configuration, see Grain storage serializers.