NewtonsoftJsonMarshaller Class
Definition
- Namespace
- Savvyio.Extensions.Newtonsoft.Json
- Assemblies
- Savvyio.Extensions.Newtonsoft.Json.dll
Provides a class for marshalling data using the Newtonsoft JSON library.
public class NewtonsoftJsonMarshaller : IMarshaller
- Inheritance
-
objectNewtonsoftJsonMarshaller
- Implements
Examples
Use NewtonsoftJsonMarshaller to serialize and deserialize Savvy I/O requests through streams.
using Savvyio;
using Newtonsoft.Json;
using Savvyio.Extensions.Newtonsoft.Json;
namespace ExampleApp;
public static class MarshallerExample
{
public static ShipOrderCommand RoundTrip(ShipOrderCommand command)
{
var marshaller = NewtonsoftJsonMarshaller.Create(options =>
{
options.Settings.Formatting = Formatting.Indented;
});
using var stream = marshaller.Serialize(command);
stream.Position = 0;
return marshaller.Deserialize<ShipOrderCommand>(stream);
}
}
public sealed record ShipOrderCommand(string OrderId) : Request;
Constructors
| Name | Description |
|---|---|
| NewtonsoftJsonMarshaller(Action<NewtonsoftJsonFormatterOptions>) | Initializes a new instance of the NewtonsoftJsonMarshaller class. |
Properties
| Name | Description |
|---|---|
| Default | Provides a default instance of the NewtonsoftJsonMarshaller class optimized for messaging. |
Methods
| Name | Description |
|---|---|
| Create(Action<NewtonsoftJsonFormatterOptions>) | Creates a new instance of the NewtonsoftJsonMarshaller class. |
| Deserialize(Stream, Type) | Deserializes the specified |
| Deserialize<TValue>(Stream) | Deserializes the specified |
| Serialize(object, Type) | Serializes the specified |
| Serialize<TValue>(TValue) | Serializes the specified |