Package Description
License
—
Deps
2
Install Size
—
Vulns
✓ 0
Published
Feb 3, 2026
$ dotnet add package Nabs.Launchpad.Core.SerialisationThe Nabs Launchpad Core Serialisation library provides centralized configuration and utilities for JSON and CSV serialization across the application. This library ensures consistent serialization behavior throughout your projects by providing global settings and convenient serializer wrappers.
The central configuration class that manages global serialization settings for both JSON and CSV formats. Provides lazy initialization with sensible defaults and allows runtime configuration overrides.
A static utility class that provides convenient methods for JSON serialization and deserialization using the configured global settings.
// Serialize an object to JSON
var user = new User { Name = "John Doe", Email = "john@example.com" };
var json = DefaultJsonSerializer.Serialize(user);
// Output: {
// "name": "John Doe",
// "email": "john@example.com"
// }
// Deserialize JSON to an object
var jsonString = """
{
"name": "Jane Doe",
"email": "jane@example.com"
}
""";
var user = DefaultJsonSerializer.Deserialize<User>(jsonString);
// Access JSON serializer options
var jsonOptions = GlobalSettings.JsonSerializerOptions;
// Default: camelCase naming policy, indented formatting
// Access CSV configuration
var csvConfig = GlobalSettings.CsvConfiguration;
// Default: InvariantCulture, headers enabled, comma delimiter
// Register custom JSON serializer options
var customOptions = new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower,
WriteIndented = false,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
};
GlobalSettings.RegisterJsonSerializerOptions(customOptions);
// All subsequent serialization will use these settings
var json = DefaultJsonSerializer.Serialize(myObject);
// Register custom CSV configuration
var customCsvConfig = new CsvConfiguration(CultureInfo.InvariantCulture)
{
HasHeaderRecord = true,
Delimiter = "|", // Use pipe delimiter instead of comma
TrimOptions = TrimOptions.Trim,
IgnoreBlankLines = true,
MissingFieldFound = null,
HeaderValidated = null
};
GlobalSettings.RegisterCsvConfiguration(customCsvConfig);
// Use the configuration with CsvHelper
using var reader = new StreamReader("data.csv");
using var csv = new CsvReader(reader, GlobalSettings.CsvConfiguration);
var records = csv.GetRecords<MyDataType>();
public static JsonSerializerOptions JsonSerializerOptions { get; }
Gets the configured JSON serializer options. Returns default settings if none have been registered.
Default Settings:
JsonNamingPolicy.CamelCasetruepublic static CsvConfiguration CsvConfiguration { get; }
Gets the configured CSV configuration. Returns default settings if none have been registered.
Default Settings:
CultureInfo.InvariantCulturetruenullnulltrue","TrimOptions.Trimpublic static void RegisterJsonSerializerOptions(JsonSerializerOptions jsonSerializerOptions)
Registers custom JSON serializer options to be used globally throughout the application.
public static void RegisterCsvConfiguration(CsvConfiguration csvConfiguration)
Registers custom CSV configuration to be used globally throughout the application.
public static string Serialize<T>(T value)
Serializes an object to a JSON string using the global JSON serializer options.
Parameters:
value: The object to serializeReturns: A JSON string representation of the object
public static T Deserialize<T>(string json)
Deserializes a JSON string to an object of the specified type using the global JSON serializer options.
Parameters:
json: The JSON string to deserializeReturns: An object of type T
When writing unit tests that use global settings, you should reset the static configuration between tests to ensure test isolation. The library includes a base test class pattern:
public abstract class BaseSerialisationUnitTest : IAsyncLifetime
{
public ValueTask InitializeAsync()
{
// Reset static members using reflection
ResetStaticMember(typeof(GlobalSettings), "_csvConfiguration");
ResetStaticMember(typeof(GlobalSettings), "_jsonSerializerOptions");
return ValueTask.CompletedTask;
}
public ValueTask DisposeAsync()
{
return ValueTask.CompletedTask;
}
private static void ResetStaticMember(Type type, string fieldName)
{
var field = type.GetField(fieldName, BindingFlags.Static | BindingFlags.NonPublic);
field?.SetValue(null, null);
}
}