Install
dotnet add package Microsoft.Orleans.Serialization.NewtonsoftJson --version 10.2.2
| Product | Versions |
|---|---|
| .NET | |
| .NET Standard |
README
Microsoft Orleans Serialization for Newtonsoft.Json
Introduction
Microsoft Orleans Serialization for Newtonsoft.Json provides JSON serialization support for Microsoft Orleans using the popular Newtonsoft.Json library. This allows you to use the comprehensive JSON features of Newtonsoft.Json within your Orleans application.
Getting Started
To use this package, install it via NuGet:
dotnet add package Microsoft.Orleans.Serialization.NewtonsoftJson
Example - Configuring Newtonsoft.Json Serialization
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Orleans.Hosting;
using Orleans.Serialization;
var builder = Host.CreateApplicationBuilder(args)
.UseOrleans(siloBuilder =>
{
siloBuilder
.UseLocalhostClustering()
// Configure Newtonsoft.Json as a serializer
.AddSerializer(serializerBuilder => serializerBuilder.AddNewtonsoftJsonSerializer(type => type.Namespace.StartsWith("ExampleGrains")));
});
// Run the host
await builder.RunAsync();
Example - Using Newtonsoft.Json with a Custom Type
using Orleans;
using Newtonsoft.Json;
namespace ExampleGrains;
// Define a class with Newtonsoft.Json attributes
public class MyJsonClass
{
[JsonProperty("full_name")]
public string Name { get; set; }
[JsonProperty("age")]
public int Age { get; set; }
[JsonProperty("tags")]
public List<string> Tags { get; set; }
[JsonIgnore]
public string SecretData { get; set; }
}
// You can use it directly in your grain interfaces and implementation
public interface IMyGrain : IGrainWithStringKey
{
Task<MyJsonClass> GetData();
Task SetData(MyJsonClass data);
}
public class MyGrain : Grain, IMyGrain
{
private MyJsonClass _data;
public Task<MyJsonClass> GetData()
{
return Task.FromResult(_data);
}
public Task SetData(MyJsonClass data)
{
_data = data;
return Task.CompletedTask;
}
}
Documentation
For more comprehensive documentation, please refer to:
Feedback & Contributing
- If you have any issues or would like to provide feedback, please open an issue on GitHub
- Join our community on Discord
- Follow the @msftorleans Twitter account for Orleans announcements
- Contributions are welcome! Please review our contribution guidelines
- This project is licensed under the MIT license
Changes from Previous Version
No structural changes between v10.2.2-rc.2 and v10.2.2.
Adoption Assessment
A verified publisher signal is available. Assess fit from the package's supported frameworks, license and dependency graph rather than popularity alone.
Compatibility metadata lists 3 target frameworks; confirm the exact target used by your application.The published metadata declares 41 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.