Table of Contents

JsonMarshaller Class

Definition

Namespace
Savvyio.Extensions.Text.Json
Assemblies
Savvyio.Extensions.Text.Json.dll
Source
src/Savvyio.Extensions.Text.Json/JsonMarshaller.cs

Provides a class for marshalling data using native JSON support in .NET.

public class JsonMarshaller : IMarshaller
Inheritance
object
JsonMarshaller
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 data into an object of returnType.

Deserialize<TValue>(Stream)

Deserializes the specified data into an object of TValue.

Serialize(object, Type)

Serializes the specified value to an object of Stream.

Serialize<TValue>(TValue)

Serializes the specified value to an object of Stream.

See Also