Skip to content

Fix root object replacement in JsonPoke#112

Merged
kzu merged 3 commits into
mainfrom
fix/85-root-poke-metadata
Jun 24, 2026
Merged

Fix root object replacement in JsonPoke#112
kzu merged 3 commits into
mainfrom
fix/85-root-poke-metadata

Conversation

@kzu

@kzu kzu commented Jun 24, 2026

Copy link
Copy Markdown
Member

Fixes #85

When Query is $, node.Replace() fails with InvalidOperationException: The parent is missing because the root token has no parent.

Changes

  • Parse JSON with JToken.Parse instead of JObject.Parse
  • Add SetToken helper that reassigns the root token when node.Parent == null instead of calling Replace
  • Add unit tests (PokeRootWithMetadata, PokeRootWithRawValue) and MSBuild integration target (PokeRootObject)

Repro (before fix)

<JsonPoke Content="{}" Query="$" Value="@(VersionFile)" Properties="a" />

With VersionFile item metadata a=Value of a, this threw at JsonPoke.cs:207.

After fix

Produces { "a": "Value of a" } as expected.

kzu added 2 commits June 24, 2026 12:46
When Query is $, node.Replace fails because the root has no parent.
Use JToken.Parse and reassign the root token instead of Replace.

Fixes #85
@kzu

kzu commented Jun 24, 2026

Copy link
Copy Markdown
Member Author

44 passed 44 passed

🧪 Details on Ubuntu 24.04.4 LTS

from retest v1.1.0 on .NET 10.0.9 with 💜 by @devlooped

@kzu kzu merged commit f9e2a0c into main Jun 24, 2026
4 checks passed
@kzu kzu deleted the fix/85-root-poke-metadata branch June 24, 2026 15:51
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.

Cannot write metadata to root object

1 participant