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
- Host: GitHub
- URL: https://github.com/ERNI-Academy/assets-serializers-abstraction
- Owner: ERNI-Academy
- License: mit
- Created: 2022-04-07T12:37:38.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-10-17T19:32:19.000Z (8 months ago)
- Last Synced: 2025-03-16T00:13:43.204Z (3 months ago)
- Topics: abstraction, messagepack, newtonsoft-json, serialization, system-text-json
- Language: C#
- Homepage:
- Size: 38.1 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
- Security: SECURITY.md
- Authors: AUTHORS.md
Awesome Lists containing this project
- awesome-resources - assets-serializers-abstraction
README
# About Serializers Abstraction
Define a contract and many implementations for working with many technologies for serialization[](#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

(LICENSE) © 2022 [ERNI - Swiss Software Engineering](https://www.betterask.erni)
## Code of conduct
Please see our [Code of Conduct](CODE_OF_CONDUCT.md)
## Stats

## Follow us
[](https://www.twitter.com/ERNI)
[](https://www.twitch.tv/erni_academy)
[](https://www.youtube.com/channel/UCkdDcxjml85-Ydn7Dc577WQ)
[](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)):
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!