SystemTextJsonHelper
is a C# helper class lib that simplifies the process of serializing and deserializing objects using the System.Text.Json
namespace. It provides a flexible and convenient way to handle JSON serialization and deserialization with customizable options.
- Serialize objects to JSON strings with customizable options.
- Deserialize JSON strings back into objects with customizable options.
- Easily set global serialization options for consistent behavior across the application.
To use the SystemTextJsonHelper
in your project, follow these steps:
- Install the package from NuGet.
- import the
SystemTextJsonHelper
namespace. - Configure global options using
SetGlobalJsonSerializerOptions
method ofJsonHelper
class. - You can get current options using
GetJsonSerializerOptions
orGetJsonSerializerOptions
to get default options. - Access static methods
Serialize
orDeserialize
from theJsonHelper
class for serialization and deserialization.
JsonHelper.SetGlobalJsonSerializerOptions(options => {
// Customize the JsonSerializerOptions here
options.IncludeFields = true;
return options;
});
var myObject = new MyCustomObject();
string json = JsonHelper.Serialize(myObject);
// With custom options:
string customJson = JsonHelper.Serialize(myObject, options => {
// Customize the JsonSerializerOptions here
options.IncludeFields = true;
return options;
});
string jsonString = "{\"propertyName\": \"propertyValue\"}";
MyCustomObject deserializedObject = JsonHelper.Deserialize<MyCustomObject>(jsonString);
// With custom options:
MyCustomObject customDeserializedObject = JsonHelper.Deserialize<MyCustomObject>(jsonString, options => {
// Customize the JsonSerializerOptions here
options.PropertyNameCaseInsensitive = true;
return options;
});
SystemTextJsonHelper
is released under the MIT License. You can find the full license details in the LICENSE file.
Made with ❤️ by NightmareGaurav.
We welcome contributions from the community. If you have suggestions, bug reports, or feature requests, please feel free to open issues or pull requests on GitHub.