An open API service indexing awesome lists of open source software.

https://github.com/ERNI-Academy/assets-serializers-abstraction

Serializer abstractions to work with System.Text.Json, Newtonsoft, Messagepack etc
https://github.com/ERNI-Academy/assets-serializers-abstraction

abstraction messagepack newtonsoft-json serialization system-text-json

Last synced: about 1 month ago
JSON representation

Serializer abstractions to work with System.Text.Json, Newtonsoft, Messagepack etc

Awesome Lists containing this project

README

        

# About Serializers Abstraction
Define a contract and many implementations for working with many technologies for serialization

[![All Contributors](https://img.shields.io/badge/all_contributors-1-orange.svg?style=flat-square)](#contributors)

## Built With

- [.Net 6.0](https://docs.microsoft.com/en-us/dotnet/core/whats-new/dotnet-6)
- [c# 11](https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-11)

## Features

- SerializeToStream
- SerializeToStreamAsync
- SerializeToString
- DeserializeFromStream
- DeserializeFromString
- DeserializeFromStreamAsync

# Getting Started
Use the latest nuget published of EA.Serializers.Contracts and the desire nuget of the implementation

## Prerequisites

- [.Net 6.0](https://docs.microsoft.com/en-us/dotnet/core/whats-new/dotnet-6)
- [c# 11](https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-11)

## Dependencies

- .Net 6.0
- System.Text.Json
- Newtonsoft
- MessagePack

## Installation

At this point, it is possible to use that asset:

- Cloning the repo and use it directly on you solution. On this way, you will have access too entire code.
- Using the dll located on Release folder

## samples

```c#
var stream = new MemoryStream();
var item = new Item(); //Item can be any obj

//you can choose between many impl
ISerializer serializer = new ErniAcademy.Serializers.Json.JsonSerializer();
ISerializer serializer = new ErniAcademy.Serializers.NewtonsoftJson.JsonSerializer();
ISerializer serializer = new ErniAcademy.Serializers.MessagePack.MessagePackSerializer(); //keep in mind that for Message pack you will need to add [DataContract] and [DataMembers] attributes

//serialize
await serializer.SerializeToStreamAsync(item, stream);
//at this point you can do what you want with the stream that contain your item, for example you can upload the stream to a blob e.g. https://docs.microsoft.com/en-us/dotnet/api/azure.storage.blobs.blobclient.uploadasync?view=azure-dotnet#azure-storage-blobs-blobclient-uploadasync(system-io-stream-system-boolean-system-threading-cancellationtoken)

//deserialize
var deserializedItem = await serializer.DeserializeFromStreamAsync(stream);
//at this point you will get your item instance
```

- take care about that sample are instances directly. In general situation, we should use DI.
- take a look at the UnitTests project to see it samples of use

## Contributing

Please see our [Contribution Guide](CONTRIBUTING.md) to learn how to contribute.

## License

![MIT](https://img.shields.io/badge/License-MIT-blue.svg)

(LICENSE) © 2022 [ERNI - Swiss Software Engineering](https://www.betterask.erni)

## Code of conduct

Please see our [Code of Conduct](CODE_OF_CONDUCT.md)

## Stats

![https://repobeats.axiom.co/api/embed/609d8a84f264ec3f0641941c785f96c854efe951.svg](https://repobeats.axiom.co/api/embed/609d8a84f264ec3f0641941c785f96c854efe951.svg)

## Follow us

[![Twitter Follow](https://img.shields.io/twitter/follow/ERNI?style=social)](https://www.twitter.com/ERNI)
[![Twitch Status](https://img.shields.io/twitch/status/erni_academy?label=Twitch%20Erni%20Academy&style=social)](https://www.twitch.tv/erni_academy)
[![YouTube Channel Views](https://img.shields.io/youtube/channel/views/UCkdDcxjml85-Ydn7Dc577WQ?label=Youtube%20Erni%20Academy&style=social)](https://www.youtube.com/channel/UCkdDcxjml85-Ydn7Dc577WQ)
[![Linkedin](https://img.shields.io/badge/linkedin-31k-green?style=social&logo=Linkedin)](https://www.linkedin.com/company/erni)

## Contact

📧 [[email protected]](mailto:[email protected])

## Contributors ✨

Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):



omaramalfi

💻 🖋 📖 🎨 🤔 🚧 ⚠️ 💡 👀

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!