refactor(serializer): utilize source-generated JSON context for seria…#4812
Merged
arturcic merged 1 commit intoGitTools:mainfrom Feb 8, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
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
VersionVariableSerializerto useVersionVariablesJsonContextfor serialization and deserialization. - Add
VersionVariablesJsonContextwith source-generation options plus a custom encoder configuration. - Extend
VersionVariablesJsonStringConverterwithReadAsPropertyName/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. |
src/GitVersion.Output/Serializer/VersionVariablesJsonContext.cs
Outdated
Show resolved
Hide resolved
30e2563 to
672e512
Compare
…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.
672e512 to
e1b34c8
Compare
|
Contributor
|
Thank you @arturcic for your contribution! |
Contributor
|
🎉 This issue has been resolved in version 6.6.0 🎉 Your GitReleaseManager bot 📦🚀 |
This was referenced Feb 16, 2026
Open
This was referenced Feb 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



This pull request refactors the JSON serialization and deserialization logic for
GitVersionVariablesby moving from manualJsonSerializerOptionssetup 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:
JsonSerializerOptionsconfiguration with the source-generatedVersionVariablesJsonContextfor both serialization and deserialization inVersionVariableSerializer. [1] [2] [3]VersionVariablesJsonContextpartial class, configuring it for indented output, custom converters, and relaxed JSON escaping.Custom converter enhancements:
ReadAsPropertyNameandWriteAsPropertyNamemethods toVersionVariablesJsonStringConverterto support correct property name handling during JSON (de)serialization.Code cleanup:
JsonSerializerOptionsmethod fromVersionVariableSerializer. [1] [2]