Skip to content

Comments

refactor(serializer): utilize source-generated JSON context for seria…#4812

Merged
arturcic merged 1 commit intoGitTools:mainfrom
arturcic:feature/json-serializer-source-generated
Feb 8, 2026
Merged

refactor(serializer): utilize source-generated JSON context for seria…#4812
arturcic merged 1 commit intoGitTools:mainfrom
arturcic:feature/json-serializer-source-generated

Conversation

@arturcic
Copy link
Member

@arturcic arturcic commented Feb 8, 2026

This pull request refactors the JSON serialization and deserialization logic for GitVersionVariables by moving from manual JsonSerializerOptions setup to using a source-generated context (VersionVariablesJsonContext). This change improves performance, maintainability, and type safety. Additionally, custom property name handling is added for JSON string conversion.

Serialization improvements:

  • Replaced manual JsonSerializerOptions configuration with the source-generated VersionVariablesJsonContext for both serialization and deserialization in VersionVariableSerializer. [1] [2] [3]
  • Introduced the new VersionVariablesJsonContext partial class, configuring it for indented output, custom converters, and relaxed JSON escaping.

Custom converter enhancements:

  • Added ReadAsPropertyName and WriteAsPropertyName methods to VersionVariablesJsonStringConverter to support correct property name handling during JSON (de)serialization.

Code cleanup:

  • Removed unused imports and the now-unnecessary JsonSerializerOptions method from VersionVariableSerializer. [1] [2]

@arturcic arturcic added this to the 6.x milestone Feb 8, 2026
@arturcic arturcic marked this pull request as ready for review February 8, 2026 12:21
Copilot AI review requested due to automatic review settings February 8, 2026 12:21
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors GitVersionVariables JSON (de)serialization in GitVersion.Output to use a source-generated JsonSerializerContext (VersionVariablesJsonContext) instead of manually constructed JsonSerializerOptions, and extends the custom string converter to support property-name conversion.

Changes:

  • Switch VersionVariableSerializer to use VersionVariablesJsonContext for serialization and deserialization.
  • Add VersionVariablesJsonContext with source-generation options plus a custom encoder configuration.
  • Extend VersionVariablesJsonStringConverter with ReadAsPropertyName / WriteAsPropertyName.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/GitVersion.Output/Serializer/VersionVariablesJsonStringConverter.cs Adds property-name conversion support to the custom string converter.
src/GitVersion.Output/Serializer/VersionVariablesJsonContext.cs Introduces a source-generated JSON context and a customized cached instance.
src/GitVersion.Output/Serializer/VersionVariableSerializer.cs Replaces manual JsonSerializerOptions usage with the source-generated context APIs.

@arturcic arturcic force-pushed the feature/json-serializer-source-generated branch 2 times, most recently from 30e2563 to 672e512 Compare February 8, 2026 13:54
…lization

Replaces manual `JsonSerializerOptions` configuration with source-generated `VersionVariablesJsonContext` for improved maintainability and performance. Removes obsolete private `JsonSerializerOptions` method and integrates the generated context in JSON methods.
@arturcic arturcic force-pushed the feature/json-serializer-source-generated branch from 672e512 to e1b34c8 Compare February 8, 2026 13:55
@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 8, 2026

@arturcic arturcic merged commit f44613e into GitTools:main Feb 8, 2026
118 checks passed
@arturcic arturcic deleted the feature/json-serializer-source-generated branch February 8, 2026 19:25
@mergify
Copy link
Contributor

mergify bot commented Feb 8, 2026

Thank you @arturcic for your contribution!

@gittools-bot
Copy link
Contributor

🎉 This issue has been resolved in version 6.6.0 🎉
The release is available on:

Your GitReleaseManager bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants