Skip to content

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

License

Notifications You must be signed in to change notification settings

ERNI-Academy/assets-serializers-abstraction

Repository files navigation

About Serializers Abstraction

Define a contract and many implementations for working with many technologies for serialization

All Contributors

Built With

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

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

 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<Item>(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 to learn how to contribute.

License

MIT

(LICENSE) © 2022 ERNI - Swiss Software Engineering

Code of conduct

Please see our Code of Conduct

Stats

https://repobeats.axiom.co/api/embed/609d8a84f264ec3f0641941c785f96c854efe951.svg

Follow us

Twitter Follow Twitch Status YouTube Channel Views Linkedin

Contact

📧 [email protected]

Contributors ✨

Thanks goes to these wonderful people (emoji key):


omaramalfi

💻 🖋 📖 🎨 🤔 🚧 ⚠️ 💡 👀

This project follows the all-contributors specification. Contributions of any kind welcome!

About

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

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors 3

  •  
  •  
  •  

Languages