fix: correct ReleaseNotes deserialization for AutoUpdater (fixes #1039)#1061
Merged
GregorBiswanger merged 3 commits intoMay 9, 2026
Merged
Conversation
- 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
Contributor
There was a problem hiding this comment.
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 convertreleaseNotesstrings and string arrays into{ note }objects. - Add a C#
JsonConverter<ReleaseNoteInfo[]>and apply it toUpdateInfo.ReleaseNotes. - Add unit tests validating all supported
releaseNotesinput 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; |
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
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(); | ||
| } |
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.
closes #1039