Skip to content

Keep a NavigationItem's CreatedAt and Metadata through a JSON round trip [minor] - #65

Merged
matt-edmondson merged 3 commits into
mainfrom
fix/navigation-item-json-round-trip
Sep 28, 2026
Merged

matt-edmondson merged 3 commits into
mainfrom
fix/navigation-item-json-round-trip

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #56

What changed

NavigationItem had only the (id, displayName) constructor. When System.Text.Json deserialized an item, it dropped the saved Metadata, because that is a get-only computed property. It also stamped CreatedAt with the load time.

  • Added a [JsonConstructor] overload, NavigationItem(string id, string displayName, DateTime createdAt, IReadOnlyDictionary<string, object>? metadata). It chains to the existing constructor, so validation is unchanged, then restores CreatedAt and copies the metadata. Entries with a null or blank key, or a null value, are skipped, which keeps SetMetadata's rules.
  • Documented that metadata values read from JSON come back as JsonElement rather than their original CLR types. This is in the XML docs and docs/API.md, and follows the triage note to keep object values instead of narrowing to string, which would break the API.
  • This adds a public constructor, so the change is tagged [minor].

Tests

🤖 Generated with Claude Code

https://claude.ai/code/session_01ScKzvHsZwsrSifP4Mbp1jW


Generated by Claude Code

…rip [minor]

NavigationItem's only constructor took the id and display name, so
System.Text.Json dropped the saved Metadata (a get-only computed property)
and gave every loaded item the load time as its CreatedAt. A new
[JsonConstructor] overload takes createdAt and metadata and restores both.
Metadata values come back as JsonElement, which the constructor docs and
docs/API.md now say.

Fixes #56

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ScKzvHsZwsrSifP4Mbp1jW
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ScKzvHsZwsrSifP4Mbp1jW
…son-round-trip

# Conflicts:
#	Navigation.Test/JsonFilePersistenceProviderTests.cs
@sonarqubecloud

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit 5c253c7 into main Sep 28, 2026
12 checks passed
@matt-edmondson
matt-edmondson deleted the fix/navigation-item-json-round-trip branch September 28, 2026 09:22
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.

NavigationItem loses Metadata and CreatedAt on a JSON save/load round-trip

2 participants