AccountingNext/Schaad.Accounting.Db/JsonStorage.cs
Claudio Schaad 24bdfe60bc Store data as JSON instead of XML, with startup migration
Repositories now read and write indented, human-readable JSON
(System.Text.Json, shared settings in JsonStorage). File names and folders
are unchanged apart from the extension.

XmlToJsonMigrator runs at startup before the app serves requests. It converts
the known Data/*.xml files under every year/mandator, verifies the JSON reads
back to the same data, and moves the XML to
{year}/backup/{mandator}/xml-{timestamp}/. Bank-statement XMLs in uploads/ are
never touched. Any failure stops startup and leaves that file's XML in place.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 13:34:23 +02:00

23 lines
830 B
C#

using System.Text.Encodings.Web;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Schaad.Accounting.Repositories
{
/// <summary>
/// Serializer settings shared by the repositories and the XML-to-JSON migration, so both
/// produce byte-identical files.
/// </summary>
public static class JsonStorage
{
public static readonly JsonSerializerOptions Options = new()
{
// Human readable: indented, and umlauts/quotes written as-is instead of \u escapes.
WriteIndented = true,
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
PropertyNameCaseInsensitive = true,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
};
}
}