6502bench icon indicating copy to clipboard operation
6502bench copied to clipboard

Update JSON serializer

Open fadden opened this issue 1 year ago • 0 comments

The project file is currently serialized and deserialized with JavaScriptSerializer from System.Web.Script.Serialization. This is an older library that lacks some features, which is why the SourceGen implementation does a series of text substitutions to add line breaks. These are useful because they make the file easier to read by humans, and provide better diffs in source code control systems.

System.Text.Json.JsonSerializer is the new & improved version; I've been using it in another project and it seems to work well. It appears to be available in .NET Framework. (Update: according to this, it must be added as a NuGet package until .NET Core 3.0, and may require 4.7.2.) It provides a WriteIndented property that produces nicely-formatted output without the clumsy text replacement.

While messing around with this it would also be good to investigate the "exclude default values" options, which would avoid storing unnecessary assignments, like null strings. This should be backward-compatible with older versions of SourceGen because the deserialization structs are initialized to defaults. Enabling this should make the project files slightly smaller. Start with JsonSerializerOptions.DefaultIgnoreCondition set to WhenWritingNull.

The JSON format is used in a number of places:

  • project files (*.dis65)
  • application settings (SourceGen-settings); values for some individual settings are serialized with JSON because it was a convenient way to store multiple items:
    • assembler configurations
    • list of recent projects
    • pseudo-op name overrides
  • the daily tips definition file
  • system definitions for new projects (RuntimeData/SystemDefs.json)
  • SGEC comment exports

fadden avatar Jun 01 '24 17:06 fadden