Skip to content

SerializationHelper is a simple wrapper around System.Text.Json to overcome some of the common challenges developers face when using Microsoft's JSON library compared to the Newtonsoft.Json library.

License

Notifications You must be signed in to change notification settings

jchristn/SerializationHelper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

SerializationHelper

SerializationHelper is a simple wrapper around System.Text.Json to overcome some of the common challenges developers face when using Microsoft's JSON library.

NuGet Version NuGet

Help, Feedback, Contribute

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!

Overview

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.

New in v2.0.x

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 JsonConverter objects

Example Project

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 Smith

Add Your Own JsonConverter

using SerializationHelper;

public class MyClassConverter : JsonConverter<MyClass>
{
  ...
}

Serializer serializer = new Serializer();
serializer.DefaultConverters.Add(new MyClassConverter());

Version History

Refer to CHANGELOG.md for version history.

About

SerializationHelper is a simple wrapper around System.Text.Json to overcome some of the common challenges developers face when using Microsoft's JSON library compared to the Newtonsoft.Json library.

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages