SerializIt 0.6.9

There is a newer version of this package available.
See the version list below for details.
dotnet add package SerializIt --version 0.6.9                
NuGet\Install-Package SerializIt -Version 0.6.9                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SerializIt" Version="0.6.9" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SerializIt --version 0.6.9                
#r "nuget: SerializIt, 0.6.9"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install SerializIt as a Cake Addin
#addin nuget:?package=SerializIt&version=0.6.9

// Install SerializIt as a Cake Tool
#tool nuget:?package=SerializIt&version=0.6.9                

<p align="center"> <img src ="https://raw.githubusercontent.com/KhaosCoders/SerializIt/master/Art/Icon.png" width=200 /> </p>

SerializIt

A super fast serializer using Roslyn SourceGenerators instead of reflection

Build Test codecov NuGet

Only supports serialization, no deserialization!

Supported Serializers

  • JSON
  • YAML
  • (basic) XML

Installation

You can find this package on nuget.org.

Install SerializIt using Package Manager Console:

Install-Package SerializIt

Or a terminal:

dotnet add package SerializIt 

Usage

Create a model you want to serialize.
Then create a partial serialization context like this

using SerializIt;
using Samples.Model;

namespace Samples
{
    [Serializer(ESerializers.Yaml)]
    [YamlOptions(indentChars: "  ")]
    [SerializeType(typeof(RootElement))]
    [SerializeType(typeof(Container))]
    [SerializeType(typeof(Info))]
    internal partial class YamlContext { }
}

This context will be augmented with a serializer for each defined type.

Call the SerializeDocument (or SerializeElement) method to serialize an object instance.

// var root = new RootElement();

var serializeIt = new YamlContext();
string text = serializeIt.RootElement.SerializeDocument(root);

Take the Samples project in this repo as an example.

Serialization should be super fast!

Benchmarks

This Benchmark compares SerializIt JSON, YAML and XML serialization with other common libraries, like Tinyhand, System.Text.Json, YamlDotNet and System.Xml.Serialization. This benchmark was run on my HP Notebook (16GB Ram, Intel i7-8565U, SSD).

Method Mean Error StdDev Median Gen 0 Gen 1 Gen 2 Allocated
TinyhandJson 428.7 us 17.17 us 48.98 us 398.2 us 49.8047 9.7656 - 207 KB
SystemTextJsonSG 221.4 us 3.41 us 3.50 us 220.3 us 38.3301 38.3301 38.3301 121 KB
SystemTextFormattedJsonSG 285.7 us 3.32 us 2.77 us 285.2 us 66.4063 66.4063 66.4063 208 KB
SerializItJson 194.2 us 0.70 us 0.58 us 194.4 us 41.5039 41.5039 41.5039 130 KB
SerializItFormattedJson 308.7 us 2.59 us 2.02 us 309.5 us 52.2461 52.2461 52.2461 164 KB
YamlDotNet 13,335.0 us 111.03 us 159.23 us 13,327.2 us 1125.0000 218.7500 31.2500 4,873 KB
SerializItYaml 206.9 us 2.53 us 2.25 us 206.9 us 41.5039 41.5039 41.5039 130 KB
XmlSerializer 628.0 us 7.36 us 6.89 us 626.4 us 54.6875 54.6875 54.6875 395 KB
SerializItXml 175.0 us 2.55 us 2.26 us 174.3 us 65.6738 65.6738 65.6738 207 KB

Conclusion

SerializIt is fast. But, if you want to serialize to and from JSON your better of with the Source Generators in System.Text.Json. When you're after YAML or XML serialization however, SerializIt is your best option. It delivers much faster serialization to these formats, than the common libraries this benchmark was performed with.

Remarks

SerializIt does only serialize object. There is no de-serialization for now. So if you need to de-serialize some YAML or XML you're again better of with the mentioned libraries, as they offer de-serialization, too. Moreover, the XML serializer comming with SerializIt is in alpha stage, at best. A lot of work needs to be done, to make it a helpfull serializer.

Features

This serializer supports the following features:

  • Formats: JSON, YAML, (basic) XML
  • PrettyPrint (JSON / XML): On/Off
  • Custom Indentation - Defaults to Tabs
  • Can skip defined properties
  • Can skip properties with default value
  • Can order properties

Pending improvements

[ ] Value Converters (serialize complex data types, like GUID or BitInteger)
[ ] Custom serializers (support custom formats)
[ ] Serializer specific member options (like CDATA for XML or Inline for Yaml & Json)
[ ] XML Namespaces
[ ] XML Attributes

Support this ❤️

If you like my work, please support this project!
Donate via PayPal or become a Sponsor on GitHub

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.6.13 171 6/4/2023
0.6.12 140 6/4/2023
0.6.11 134 6/4/2023
0.6.10 139 6/4/2023
0.6.9 131 6/4/2023
0.6.8 135 6/4/2023
0.6.6 136 6/4/2023
0.6.5 133 6/4/2023
0.6.4 142 6/4/2023
0.6.3 133 6/4/2023
0.6.2 147 6/4/2023
0.6.1 133 6/4/2023
0.6.0 135 6/4/2023
0.5.7 140 6/2/2023
0.5.6 138 6/2/2023
0.5.5 144 6/2/2023
0.5.4 147 5/6/2023
0.5.3 137 5/6/2023
0.5.2 140 5/6/2023
0.5.1 140 5/6/2023
0.5.0 148 5/5/2023
0.4.0 181 4/21/2023