JSON Serialization with H.Necessaire

H.Necessaire's mechanism for JSON serialization

JSON Serialization with H.Necessaire
Photo by Claudio Schwarz / Unsplash
H.Necessaire.Usage.Samples/Src/H.Necessaire.Samples/H.Necessaire.Samples.Serialzation/Program.cs at master · hinteadan/H.Necessaire.Usage.Samples
Usage Samples for H.Necessaire Docs WebSite. Contribute to hinteadan/H.Necessaire.Usage.Samples development by creating an account on GitHub.

NuGets

dotnet add package H.Necessaire.Serialization

H.Necessaire.Serialization

Usage

SomeData data = new SomeData { Name = "Hintee" };

SomeData[] dataArray = [data, data];

string jsonObjectString = data.ToJsonObject();

string jsonArrayString = dataArray.ToJsonArray();

SomeData deserializedData = jsonObjectString.JsonToObject<SomeData>();

SomeData[] deserializedArray = jsonArrayString.JsonToObject<SomeData[]>();
ToJsonObject() works on collections as well, obviously, but using ToJsonArray() will check for empty collections and use the provided default value in that case.