{"id":21514178,"url":"https://github.com/greentube/serialization","last_synced_at":"2025-09-11T01:33:30.300Z","repository":{"id":75456532,"uuid":"111313172","full_name":"Greentube/serialization","owner":"Greentube","description":"Common serialization abstraction with multiple implementations","archived":false,"fork":false,"pushed_at":"2017-12-03T22:46:00.000Z","size":209,"stargazers_count":5,"open_issues_count":6,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-02T20:46:54.720Z","etag":null,"topics":["json","messagepack","protobuf","serialization","xml"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Greentube.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-11-19T16:39:46.000Z","updated_at":"2023-04-16T03:16:27.000Z","dependencies_parsed_at":"2023-06-09T00:45:26.863Z","dependency_job_id":null,"html_url":"https://github.com/Greentube/serialization","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Greentube%2Fserialization","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Greentube%2Fserialization/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Greentube%2Fserialization/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Greentube%2Fserialization/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Greentube","download_url":"https://codeload.github.com/Greentube/serialization/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248103909,"owners_count":21048244,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["json","messagepack","protobuf","serialization","xml"],"created_at":"2024-11-23T23:43:08.616Z","updated_at":"2025-04-09T19:50:38.555Z","avatar_url":"https://github.com/Greentube.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Greentube.Serialization [![Build Status](https://travis-ci.org/Greentube/serialization.svg?branch=master)](https://travis-ci.org/Greentube/serialization) [![Build status](https://ci.appveyor.com/api/projects/status/2ib0oivho3ftgws2/branch/master?svg=true)](https://ci.appveyor.com/project/Greentube/serialization) [![codecov](https://codecov.io/gh/Greentube/serialization/branch/master/graph/badge.svg)](https://codecov.io/gh/Greentube/serialization)\n\nA set of libraries for serialization which work as a **common interface for serialization**. It includes multiple implementations available for use.\n\nEach project under `src` contains its own documentation and a link to its NuGet package.\nOne of such packages is the convenience package [Greentube.Serialization.All](https://github.com/Greentube/serialization/tree/master/src/Greentube.Serialization.All) which is a metapackage that allows bringing all dependencies with one reference: [![NuGet](https://img.shields.io/nuget/v/Greentube.Serialization.All.svg)](https://www.nuget.org/packages/Greentube.Serialization.All/)\n\n```shell\ndotnet add package Greentube.Serialization.All\n```\n\nAlthough optional, it provides one-line configuration for applications using [Microsoft.Extensions.DependencyInjection](https://github.com/aspnet/DependencyInjection).\n\n## Implementations\n\nThe supported serialization formats are:\n\n* MessagePack - with [MessagePack-CSharp](https://github.com/neuecc/MessagePack-CSharp)\n* ProtoBuf - with [protobuf-net](https://github.com/mgravell/protobuf-net)\n* JSON - with [Newtonsoft.Json](https://github.com/JamesNK/Newtonsoft.Json)\n* XML - with [System.Xml.XmlSerializer](https://github.com/dotnet/corefx/tree/master/src/System.Xml.XmlSerializer)\n\n### Adding to your project\n\n#### With Microsoft.Extensions.DependencyInjection\n\nAll of the above can be 'plugged-in' with a single line when using the Serialization.DependencyInjection.* packages.\nExample serialization setup:\n\n```shell\ndotnet add package Greentube.Serialization.DependencyInjection.Json\n```\n\nThen JSON can be added with:\n\n```csharp\nservices.AddJsonSerializer();\n```\n\nOther packages:\n\n```shell\ndotnet add package Greentube.Serialization.DependencyInjection.Xml\ndotnet add package Greentube.Serialization.DependencyInjection.ProtoBuf\ndotnet add package Greentube.Serialization.DependencyInjection.MessagePack\n```\n\n```csharp\nservices.AddXmlSerializer();\n// or\nservices.AddProtoBufSerializer();\n// or\nservices.AddMessagePackSerializer();\n```\n\nOr with the builder:\n\n```csharp\nservices.AddSerialization(builder =\u003e\n    {\n        builder.AddMessagePack();\n        // or\n        builder.AddProtoBuf();\n        // or\n        builder.AddJson();\n        // or\n        builder.AddXml();\n    });\n```\n\n### Without dependency injection or using other containers\n\nIf you are using another container like Autofac, Castle Windsor or not using any container at all, you can avoid bringing the Microsoft.Extensions.DependencyInjection dependencies.\nJust reference the implementation you want to use directly:\n\n```shell\ndotnet add package Greentube.Serialization.MessagePack\n```\n\nThen MessagePack can be used:\n\n```csharp\nvar messagePack = new MessagePackSerializer();\n```\n\nLikewise with the other implementations:\n\n```shell\ndotnet add package Greentube.Serialization.Json\ndotnet add package Greentube.Serialization.Xml\ndotnet add package Greentube.Serialization.ProtoBuf\n```\n\n```csharp\nnew JsonSerializer();\nnew XmlSerializer();\nnew ProtoBufSerializer();\n```\n\n## Configuration\n\nEach implementation has some additional settings\n\n### MessagePack\n\nDefine a custom IFormatterResolver and compressiong LZ4:\n\n```csharp\n\nbuilder.AddMessagePack(o =\u003e {\n    // Don't require attributes on model\n    o.FormatterResolver = global::MessagePack.Resolvers.ContractlessStandardResolver.Instance;\n    // Use LZ4 compression\n    o.UseLz4Compression = true;\n});\n```\n\n### ProtoBuf\n\nCustom RuntimeTypeModel\n\n```csharp\nvar model = RuntimeTypeModel.Create();\nmodel.Add(typeof(SomeMessage), false).Add(1, nameof(SomeMessage.Body));\nbuilder.AddProtoBuf(o =\u003e o.RuntimeTypeModel = model);\n```\n\n### JSON\n\nDefine the encoding.\n\n```csharp\n// Use UTF-16 instead of the default UTF-8\nbuilder.AddJson(o =\u003e o.Encoding = Encoding.Unicode);\n```\n\n### XML\n\nXml with user-defined default namespace\n\n```csharp\nbuilder.AddXml(p =\u003e p.DefaultNamespace = \"some-namespace\");\n```\n\nXml with user-defined factory delegate\n\n```csharp\n// Root attribute will be named: 'messaging'\nbuilder.AddXml(p =\u003e p.Factory = type =\u003e new XmlSerializer(type, new XmlRootAttribute(\"messaging\")));\n```\n\n## Highlights\n\n* Simple abstraction\n* Multiple serialization formats supported\n* Pay for play: no unwanted dependencies\n* DI packages to consume with single line of code\n\n**This library was created mainly to support [Greentube.Messaging](https://github.com/Greentube/messaging).**","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgreentube%2Fserialization","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgreentube%2Fserialization","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgreentube%2Fserialization/lists"}