Skip to content

Migrate from Newtonsoft.Json to System.Text.Json with Source Generation - #85

Open
Lakritzator with Copilot wants to merge 5 commits into
masterfrom
copilot/replace-json-net-with-system-text-json
Open

Lakritzator with Copilot wants to merge 5 commits into
masterfrom
copilot/replace-json-net-with-system-text-json

Conversation

Copilot AI commented Dec 24, 2025 •

Copy link
Copy Markdown
Contributor

Replaced JSON.NET with System.Text.Json throughout the library to use modern .NET serialization and eliminate security vulnerabilities.

Changes

Dependencies

  • Added System.Text.Json 9.0.1 (fixes CVE in 8.0.4)
  • Removed Newtonsoft.Json 13.0.3
  • Removed Dapplo.HttpExtensions.JsonNet 1.1.2

Attribute Migration (100+ entity files)

  • [JsonProperty("name")] → [JsonPropertyName("name")]
  • [JsonObject] → removed (unnecessary in System.Text.Json)
  • StringEnumConverter → JsonStringEnumConverter
  • CustomDateTimeOffsetConverter → JiraDateTimeOffsetConverter

Core Infrastructure

  • Created SystemTextJsonSerializer : IJsonSerializer to replace JsonNetJsonSerializer
  • Created JiraJsonSerializerOptions for shared serialization configuration
  • Created JiraJsonContext with source generation support for .NET 6+ (AOT-friendly, high-performance)
  • Updated JiraClient to use new serializer

Source Generation

  • Implemented compile-time JSON serialization for .NET 6.0 and greater
  • Automatically activated when targeting modern .NET frameworks
  • Provides better performance and AOT compatibility
  • Falls back to reflection-based serialization for .NET Framework 4.8.1
  • Includes all major entity types (Issue, User, Project, Board, Sprint, etc.) and collections

Code Patterns

// Before: Newtonsoft.Json
var jsonContent = new JObject { { "username", username }, { "password", password } };
var content = new StringContent(jsonContent.ToString(Formatting.None));

// After: System.Text.Json
var credentials = new { username, password };
var json = JsonSerializer.Serialize(credentials, JiraJsonSerializerOptions.Default);
var content = new StringContent(json);
// Before: JArray/JToken manipulation
if (!(customField is JArray jArray)) return null;
return jArray[0]?.ToObject<Sprint>();

// After: JsonElement
if (!(customField is JsonElement jsonElement)) return null;
var jArray = jsonElement.EnumerateArray().ToArray();
return JsonSerializer.Deserialize<Sprint>(jArray[0].GetRawText(), JiraJsonSerializerOptions.Default);

Dependency Impact

System.Text.Json is now required:

  • Built-in for .NET 5.0+
  • NuGet package for .NET Framework 4.8.1
  • More performant than JSON.NET, actively maintained, no security vulnerabilities
  • Source generation provides additional performance benefits for .NET 6+
Original prompt

This section details on the original issue you should resolve

<issue_title>Replace the usage of json.net with System.Text.Json</issue_title>
<issue_description>Replace the usage of json.net with System.Text.Json, if possible with code generation.
Is it possible to remov3 the need for a dependency on System.Text.Json for the project using Dapplo.Jira?</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copilot AI and others added 3 commits December 24, 2025 23:47
… core files

Co-authored-by: Lakritzator <708125+Lakritzator@users.noreply.github.com>
Co-authored-by: Lakritzator <708125+Lakritzator@users.noreply.github.com>
Co-authored-by: Lakritzator <708125+Lakritzator@users.noreply.github.com>
@Lakritzator

Copy link
Copy Markdown
Member

@copilot What about using source generation?

Copilot AI changed the title [WIP] Replace json.net with System.Text.Json Migrate from Newtonsoft.Json to System.Text.Json Dec 24, 2025
Copilot AI requested a review from Lakritzator December 24, 2025 23:58
Co-authored-by: Lakritzator <708125+Lakritzator@users.noreply.github.com>

Copilot AI commented Dec 25, 2025

Copy link
Copy Markdown
Contributor Author

@copilot What about using source generation?

Added source generation support in commit fa0d8eb. Created JiraJsonContext that automatically activates for .NET 6+ targets, providing AOT-friendly, high-performance serialization. For .NET Framework 4.8.1, it continues using reflection-based serialization. The source generation context includes all major entity types (Issue, User, Project, Board, etc.) and their collections.

Copilot AI changed the title Migrate from Newtonsoft.Json to System.Text.Json Migrate from Newtonsoft.Json to System.Text.Json with Source Generation Dec 25, 2025
@Lakritzator
Lakritzator marked this pull request as ready for review December 25, 2025 00:05

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace the usage of json.net with System.Text.Json

3 participants