Skip to content

fix: correct ReleaseNotes deserialization for AutoUpdater (fixes #1039)#1061

Merged
GregorBiswanger merged 3 commits into
developfrom
feature/fix-1039-autoupdater-releasenotes
May 9, 2026
Merged

fix: correct ReleaseNotes deserialization for AutoUpdater (fixes #1039)#1061
GregorBiswanger merged 3 commits into
developfrom
feature/fix-1039-autoupdater-releasenotes

Conversation

@GregorBiswanger
Copy link
Copy Markdown
Member

  • TypeScript normalize() now maps string releaseNotes to { note } objects and also handles arrays of strings (both cases were broken in PR Fixed Serialization of Release Notes #1041)
  • Added ReleaseNotesConverter (JsonConverter<ReleaseNoteInfo[]>) as defensive C# layer that handles all shapes: null, string, string[], object[]
  • Added [JsonConverter] attribute on UpdateInfo.ReleaseNotes
  • Added unit tests (no Electron required) covering all four input shapes

closes #1039

- TypeScript normalize() now maps string releaseNotes to { note } objects
  and also handles arrays of strings (both cases were broken in PR #1041)
- Added ReleaseNotesConverter (JsonConverter<ReleaseNoteInfo[]>) as defensive
  C# layer that handles all shapes: null, string, string[], object[]
- Added [JsonConverter] attribute on UpdateInfo.ReleaseNotes
- Added unit tests (no Electron required) covering all four input shapes
Copilot AI review requested due to automatic review settings May 9, 2026 15:35
Copy link
Copy Markdown
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

Note

Copilot was unable to run its full agentic suite in this review.

Fixes AutoUpdater releaseNotes deserialization by normalizing polymorphic JSON shapes (string / string[] / object[] / null) into ReleaseNoteInfo[], with additional defensive handling and tests for the regression reported in #1039.

Changes:

  • Update TypeScript normalize() to convert releaseNotes strings and string arrays into { note } objects.
  • Add a C# JsonConverter<ReleaseNoteInfo[]> and apply it to UpdateInfo.ReleaseNotes.
  • Add unit tests validating all supported releaseNotes input shapes.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/ElectronNET.IntegrationTests/Tests/UpdateInfoSerializationTests.cs Adds deserialization tests covering multiple releaseNotes JSON shapes
src/ElectronNET.Host/api/autoUpdater.ts Fixes JS-side normalization to produce ReleaseNoteInfo-shaped entries
src/ElectronNET.API/Converter/ReleaseNotesConverter.cs Introduces C# converter to accept polymorphic releaseNotes payloads
src/ElectronNET.API/API/Entities/UpdateInfo.cs Annotates ReleaseNotes with the new converter

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +68 to +88
public override void Write(Utf8JsonWriter writer, ReleaseNoteInfo[] value, JsonSerializerOptions options)
{
if (value is null || value.Length == 0)
{
writer.WriteNullValue();
return;
}

writer.WriteStartArray();
foreach (var item in value)
{
writer.WriteStartObject();
if (item.Version is not null)
{
writer.WriteString("version", item.Version);
}
writer.WriteString("note", item.Note);
writer.WriteEndObject();
}
writer.WriteEndArray();
}
Comment on lines +48 to +54
using var doc = JsonDocument.ParseValue(ref reader);
var entry = new ReleaseNoteInfo();
if (doc.RootElement.TryGetProperty("version", out var version))
entry.Version = version.GetString();
if (doc.RootElement.TryGetProperty("note", out var note))
entry.Note = note.GetString();
list.Add(entry);
using System.Text.Json;
using System.Text.Json.Serialization;

namespace ElectronNET.Converter;
Copy link
Copy Markdown
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

Copilot reviewed 5 out of 6 changed files in this pull request and generated 4 comments.

Comment on lines +68 to +74
public override void Write(Utf8JsonWriter writer, ReleaseNoteInfo[] value, JsonSerializerOptions options)
{
if (value is null || value.Length == 0)
{
writer.WriteNullValue();
return;
}
Comment on lines +48 to +53
using var doc = JsonDocument.ParseValue(ref reader);
var entry = new ReleaseNoteInfo();
if (doc.RootElement.TryGetProperty("version", out var version))
entry.Version = version.GetString();
if (doc.RootElement.TryGetProperty("note", out var note))
entry.Note = note.GetString();
Comment on lines +64 to +66
// Null releaseNotes should result in an empty array (matching the default value).
[Fact]
public void Deserialize_WithNullReleaseNotes_ShouldReturnEmptyArray()
/// Gets or sets the release notes.
/// </summary>
[JsonConverter(typeof(ReleaseNotesConverter))]
public ReleaseNoteInfo[] ReleaseNotes { get; set; } = new ReleaseNoteInfo[0];
- Fix namespace: ElectronNET.Converter -> ElectronNET.API.Converter
- Replace JsonDocument.ParseValue() with JsonSerializer.Deserialize<ReleaseNoteInfo>()
  for cleaner, allocation-free object array parsing
- Fix Write(): empty ReleaseNoteInfo[] now serializes as [] instead of null
- Use Array.Empty<ReleaseNoteInfo>() in UpdateInfo default initializer
- Add tests: Serialize_WithEmptyReleaseNotes and Serialize_WithNullReleaseNotes
Copy link
Copy Markdown
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

Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.

Comment on lines +111 to +112

json.Should().NotContain("releaseNotes");
Comment on lines +79 to +88
foreach (var item in value)
{
writer.WriteStartObject();
if (item.Version is not null)
{
writer.WriteString("version", item.Version);
}
writer.WriteString("note", item.Note);
writer.WriteEndObject();
}
@GregorBiswanger GregorBiswanger merged commit d7e1a09 into develop May 9, 2026
3 of 31 checks passed
@GregorBiswanger GregorBiswanger deleted the feature/fix-1039-autoupdater-releasenotes branch May 9, 2026 16:18
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.

2 participants