SerializationHelper is a simple wrapper around System.Text.Json to overcome some of the common challenges developers face when using Microsoft's JSON library.
If you have any issues or feedback, please file an issue here in Github. We'd love to have you help by contributing code for new features, optimization to the existing codebase, ideas for future releases, or fixes!
This project was built to provide a simple interface over System.Text.Json. Let's face it. Migrating from the wonderful Newtonsoft.Json package wasn't as easy as anyone expected. Microsoft's implementation is strong but has strong opinions and doesn't, as of the creation of this library, provide the same level of out-of-the-box experience as the Newtonsoft implementation.
This library is my attempt at trying to make the Microsoft implementation behave in a manner consistent to what I experienced while using the Newtonsoft implementation.
v2.0.x
- Migrate from a static class
- Allow users to add their own default
JsonSerializerOptions - Allow users to add and manage their own default list of
JsonConverterobjects
Refer to the Test project for exercising the library.
using SerializationHelper;
public class Person
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}
Serializer serializer = new Serializer();
Person p1 = new Person { Id = 10, FirstName = "Joe", LastName = "Smith" };
Console.WriteLine(serializer.SerializeJson(p1, false)); // false = not pretty print
// {"Id":10,"FirstName":"Joe","LastName":"Smith"}
Person p2 = serializer.DeserializeJson<Person>("{\"Id\":10,\"FirstName\":\"Joe\",\"LastName\":\"Smith\"}");
Console.WriteLine(p2.Id + ": " + p2.FirstName + " " + p2.LastName);
// 10: Joe Smithusing SerializationHelper;
public class MyClassConverter : JsonConverter<MyClass>
{
...
}
Serializer serializer = new Serializer();
serializer.DefaultConverters.Add(new MyClassConverter());Refer to CHANGELOG.md for version history.
