JsonMarshaller Class
Definition
- Namespace
- Savvyio.Extensions.Text.Json
- Assemblies
- Savvyio.Extensions.Text.Json.dll
Provides a class for marshalling data using native JSON support in .NET.
public class JsonMarshaller : IMarshaller
- Inheritance
-
objectJsonMarshaller
- Implements
Examples
Use JsonMarshaller to serialize and deserialize Savvy I/O requests with System.Text.Json.
using Savvyio;
using System.Text.Json;
using Savvyio.Extensions.Text.Json;
namespace ExampleApp;
public static class MarshallerExample
{
public static ShipOrderCommand RoundTrip(ShipOrderCommand command)
{
var marshaller = JsonMarshaller.Create(options =>
{
options.Settings.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
options.Settings.WriteIndented = true;
});
using var stream = marshaller.Serialize(command);
stream.Position = 0;
return marshaller.Deserialize<ShipOrderCommand>(stream);
}
}
public sealed record ShipOrderCommand(string OrderId) : Request;
Constructors
| Name | Description |
|---|---|
| JsonMarshaller(Action<JsonFormatterOptions>) | Initializes a new instance of the JsonMarshaller class. |
Properties
| Name | Description |
|---|---|
| Default | Provides a default instance of the JsonMarshaller class optimized for messaging. |
Methods
| Name | Description |
|---|---|
| Create(Action<JsonFormatterOptions>) | Creates a new instance of the JsonMarshaller 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 |