Shuttle.Core.Serialization
Installation
bash
dotnet add package Shuttle.Core.SerializationThe following implementation of the ISerializer interface is used to serialize objects into a Stream:
JsonSerializermakes use of theSystem.Text.Jsonserialization functionality.
Usage
JsonSerializer
c#
services.AddJsonSerializer(builder => {
builder.Options = new JsonSerializerOptions
{
};
// or
builder.Options.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
});The builder.Options is of type JsonSerializerOptions.
Methods
Serialize
c#
Task<Stream> SerializeAsync(object instance, CancellationToken cancellationToken = default);Returns the object as a Stream.
Deserialize
c#
Task<object> DeserializeAsync(Type type, Stream stream, CancellationToken cancellationToken = default);Deserializes the Stream into an object of the given type.