Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update JSON serializer #159

Open
fadden opened this issue Jun 1, 2024 · 0 comments
Open

Update JSON serializer #159

fadden opened this issue Jun 1, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@fadden
Copy link
Owner

fadden commented Jun 1, 2024

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 fadden changed the title Update javascript serializer Update JSON serializer Jun 1, 2024
@fadden fadden added the enhancement New feature or request label Jun 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant