Skip to content

Added Enum Converter to Respect EnumMemberAttribute - #1132

Merged
FlorianRappl merged 2 commits into
ElectronNET:developfrom
AeonSake:enum-fix
Nov 26, 2026
Merged

FlorianRappl merged 2 commits into
ElectronNET:developfrom
AeonSake:enum-fix

Conversation

@AeonSake

Copy link
Copy Markdown
Contributor

As the title says, the current enum serialization completely ignores the EnumMember attribute which causes all enum members that have different string representations than their enum label to serialize incorrectly. I noticed this issue when investigating the vibrancy option on macOS (specifically under-window). I added a custom converter that resolves the EnumMember attribute on enum fields.

I suspect this was caused by moving from Newtonsoft.Json to System.Text.Json which ignores the EnumMember attribute (Newtonsoft.Json respected that attribute). System.Text.Json has an equivalent JsonStringEnumMemberName attribute but that only ships with net9.0 or newer.

@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

pr-comment: Run #178

Tests 📝 Passed ✅ Failed ❌ Skipped ⏭️ Pending ⏳ Other ❓ Flaky 🍂 Duration ⏱️
1764 1624 0 0 0 140 0 3m 17s

🎉 All tests passed!

Github Test Reporter by CTRF 💚

🔄 This comment has been updated

@FlorianRappl FlorianRappl added this to the 0.7.0 milestone Nov 26, 2026

@FlorianRappl FlorianRappl left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The replacement enum converter breaks enum-keyed dictionaries, mishandles numeric bounds, and changes unnamed enum values from numbers to strings, regressing supported IPC and HostHook payloads.

3 open issues
What changed in this PR

This PR updates ElectronNET’s shared JSON serialization to honor custom enum names, addressing values such as macOS vibrancy’s under-window.

Changes:

  • Adds an enum converter that respects EnumMember and JsonPropertyName attributes, with camel-case fallback.
  • Registers the converter in the shared serializer options.
  • Adds tests for annotated names, nested options, deserialization, numeric inputs, and nullable enums.
File Description
src/​ElectronNET.IntegrationTests/​Tests/​EnumSerializationTests.cs Adds enum serialization and deserialization tests.
src/​ElectronNET.API/​Serialization/​EnumMemberStringEnumConverter.cs Implements attribute-aware enum conversion.
src/​ElectronNET.API/​Serialization/​ElectronJson.cs Replaces the built-in converter with the custom converter.

Review effort: Balanced

Refactor enum serialization methods to improve handling of numeric values and property names.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@FlorianRappl
FlorianRappl merged commit a72aeb0 into ElectronNET:develop Nov 26, 2026
15 checks passed
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.

3 participants