Skip to content

DI/IoC agnostic interfaces for injecting any serialization library.

License

Notifications You must be signed in to change notification settings

Open-NET-Libraries/Open.Serialization

Repository files navigation

Open.Serialization

DI/IoC agnostic interfaces for injecting any serialization library.

Implementation

With the following libraries, you can build other libraries that sever their dependency from any serializer and allow you to inject whichever you want. You can also easily integrate another serializer and still retain the DI/IoC happiness.

Core Interfaces & Extensions

https://www.nuget.org/packages/Open.Serialization
NuGet Core package for serializing anything.

https://www.nuget.org/packages/Open.Serialization.Json
NuGet Core package specific to JSON.

Library/Vendor Specific Implementations

services.AddJsonSerializer();

The following libs contain support for Microsoft.Extensions.DependencyInjection.
Import any of these and you can use the above extension to inject default serializers.

https://www.nuget.org/packages/Open.Serialization.Json.Newtonsoft
NuGet Extensions and DI for Newtonsoft.Json.

https://www.nuget.org/packages/Open.Serialization.Json.System
NuGet Extensions and DI for System.Text.Json. Note: There is no IJsonObjectSerializer option for System.Text.Json.

https://www.nuget.org/packages/Open.Serialization.Json.Utf8Json
NuGet Extensions and DI for Utf8Json.

Interface & Methods Exposed

T IDeserialize.Deserialize<T>(string value);
T IDeserialize<T>.Deserialize(string value);
object IDeserializeObject.Deserialize(string value, Type type);

ValueTask<T> IDeserializeAsync.DeserializeAsync<T>(Stream source, CancellationToken cancellationToken = default);
ValueTask<T> IDeserializeAsync<T>.DeserializeAsync(Stream source, CancellationToken cancellationToken = default);
ValueTask<object> IDeserializeObjectAsync.DeserializeAsync(Stream source, Type type, CancellationToken cancellationToken = default);

string ISerialize.Serialize<T>(T item);
string ISerialize<T>.Serialize(T item);
string ISerializeObject.Serialize(object item, Type type);

ValueTask ISerializeAsync.SerializeAsync<T>(Stream target, T item, CancellationToken cancellationToken = default);
ValueTask ISerializeAsync<T>.SerializeAsync(Stream target, T item, CancellationToken cancellationToken = default);
ValueTask ISerializeObjectAsync.SerializeAsync(Stream target, object item, Type type, CancellationToken cancellationToken = default);