Table of Contents

NewtonsoftJsonMarshaller Class

Definition

Namespace
Savvyio.Extensions.Newtonsoft.Json
Assemblies
Savvyio.Extensions.Newtonsoft.Json.dll
Source
src/Savvyio.Extensions.Newtonsoft.Json/NewtonsoftJsonMarshaller.cs

Provides a class for marshalling data using the Newtonsoft JSON library.

public class NewtonsoftJsonMarshaller : IMarshaller
Inheritance
object
NewtonsoftJsonMarshaller
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 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