lazydata 0.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package lazydata --version 0.1.0                
NuGet\Install-Package lazydata -Version 0.1.0                
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="lazydata" Version="0.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add lazydata --version 0.1.0                
#r "nuget: lazydata, 0.1.0"                
#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 lazydata as a Cake Addin
#addin nuget:?package=lazydata&version=0.1.0

// Install lazydata as a Cake Tool
#tool nuget:?package=lazydata&version=0.1.0                

LazyData

A quick data (de)serialization framework for varying data formats in .net with a focus on clean and minimal serialized output for each format, mainly for game development scenarios such as in Unity, MonoGame etc.

Build Status Join Gitter Chat

Formats supported

  • Json (via some JSON.Net implementation)
  • Xml
  • Binary

If you are interested in how the outputs would look take a look here

Examples

If you are SUPER lazy you can use the SuperLazy.Transformer to get stuff done like a typical serialization framework:

var modelIn = new SomeModel();
var data = Transformer.ToJson(modelIn);
var modelOut = Transformer.FromJson(data);

You can even lazily transform your data between formats on the fly, which is helpful if you debug in JSON but want to use Binary for production, here is an example of one of the tests:

var model = SerializationTestHelper.GeneratePopulatedModel();

var expectdString = Transformer.ToJson(model);
var xml = Transformer.FromJsonToXml(expectdString);
var binary = Transformer.FromXmlToBinary(xml);
var json = Transformer.FromBinaryToJson(binary);

Assert.AreEqual(expectdString, json);

Non Lazy Approach

The static transformer is there for people who dont care about customizing the library and just want to (de)serialize everything however the library was built to be configurable so you can skip the helper Transformer class and make the serializers yourself like so:

public class SomeClass
{
    public float SomeValue { get; set; }
}

var mappingRegistry = new MappingRegistry(new EverythingTypeMapper());
var serializer = new JsonSerializer(_mappingRegistry);
var output = serializer.Serialize(model);
Console.WriteLine("FileSize: " + output.AsString.Length + " bytes");
Console.WriteLine(output.AsString);

Deserialize stuff

var someDataFromAFile = getData();
var dataObject = new DataObject(someDataFromAFile);

var mappingRegistry = new MappingRegistry(new EverythingTypeMapper());
var deserializer = new JsonSerializer(_mappingRegistry);
var model = deserializer.Deserialize<TypeOfModel>(dataObject);

You can alternatively use an DefaultTypeMapper instead of the EverythingTypeMapper which will only attempt to serialize things with attributes on. The allowing you to not need any custom attributes. This is handy for scenarios where you just treat your models as pure data classes.

Only serialize certain properties

[Persist]
public class SomeClass
{
    [PersistData]
    public float SomeValue { get; set; }

    public string NotPersisted { get; set; }
}

var mappingRegistry = new MappingRegistry(new DefaultTypeMapper());
var serializer = new JsonSerializer(_mappingRegistry);
var output = serializer.Serialize(model);

Console.WriteLine("FileSize: " + output.AsString.Length + " bytes");
Console.WriteLine(output.AsString);

The [Persist] attribute indicates that this should be output in the serialized data, on a class it indicates it is a root object that contains serialized data, on a property it indicates the property should be mapped.

This attribute is used rather than [Serialize] because it is due to it being originally meant for ETL processes, if you want to just treat it like a serialization framework you can bypass the need for attributes entirely.

Docs

Check out the docs directory for docs which go into more detail.

Tests

There are a suite of unit tests which verify most scenarios, as well as output some performance related stats, it is recommended you take a peek at them if you want to see more advanced scenarios.

Blurb

This was originally part of the Persistity library for unity (which was originally part of EcsRx library), however was separated out to make more generic and reuseable and although its still meant to be used as a smaller part of a larger process, it has some helpers to allow it to be used just like a basic serializer without much effort.

The original focus of this library was to provide a consistent way to pass data around and convert/transform it between formats and types easily however as the serialization pieces can be used in isolation purely for serialization

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.

NuGet packages (6)

Showing the top 5 NuGet packages that depend on lazydata:

Package Downloads
LazyData.Binary

Binary serializer for use with LazyData

lazydata.superlazy

A super lazy helper class to statically access serializers

LazyData.Json

Json serializer for use with LazyData

LazyData.Xml

Xml serializer for use with LazyData

LazyData.Numerics

Add default handling for System.Numerics.Vectors

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.0.17 13,911 3/18/2020
2.0.11 3,719 12/19/2018
2.0.9 2,759 11/26/2018
1.1.7 2,938 11/15/2018
1.0.5 2,842 11/7/2018
1.0.3 2,800 11/7/2018
0.3.2 2,964 9/20/2018
0.3.1 2,881 9/20/2018
0.3.0 2,975 9/20/2018
0.2.21 1,987 9/18/2018
0.2.20 2,041 9/18/2018
0.2.19 1,988 9/18/2018
0.2.0 2,833 9/12/2018
0.1.0 2,133 2/16/2018

Initial release