Marshal Any as the node it wraps instead of {"Node": ...}
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 65/100
Research direction
Start by reading the definition of Any and its existing UnmarshalJSON method, then inspect how tree.MarshalJSON and MarshalYAML encode nodes. Add coverage for wrapped map values and nil nodes, including Any{} and a typed nil array. Done means JSON and YAML encode the wrapped value directly, nil nodes encode as null, and the release note mentions the output change.
Written by the indexing model from the issue text.
Description
Any exists so that a struct field can hold any JSON value (Node is an interface, so encoding/json cannot decode into it), and (*Any).UnmarshalJSON decodes into the wrapped node. There is no MarshalJSON / MarshalYAML, so encoding marshals the struct itself and the round trip breaks:
type Config struct {
Name string `json:"name"`
Extra tree.Any `json:"extra"`
}
json.Unmarshal([]byte(`{"name":"a","extra":{"k":1}}`), &c) // c.Extra.Node == Map{"k": 1}
json.Marshal(c) // {"name":"a","extra":{"Node":{"k":1}}}
tree.MarshalJSON(tree.Map{"a": tree.Any{Node: tree.StringValue("x")}}) gives {"a":{"Node":"x"}} and MarshalYAML gives node: x under a, while ColorEncoder (tq's colored output) prints {"a": "x"}.
Proposal: add Any.MarshalJSON and Any.MarshalYAML that encode the wrapped node, and encode null when it is a Go nil node (Any{}, which is the zero value of an absent field, or Any{Node: (*Array)(nil)}), matching how #184 reads such an Any as null.
| Value | JSON | YAML |
|---|---|---|
Any{Node: Map{"k": 1}} |
{"k":1} |
k: 1 |
Any{} / Any{Node: (*Array)(nil)} |
null |
null |
This changes the output for anyone relying on the {"Node": ...} shape, which cannot be decoded back, so it belongs in the release note.
- Dominant language
- Go
- Stars
- 7
- Forks
- 2
- Avg merge
- 11h 12m
- Merged PRs (30d)
- 43
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from mojatter/tree
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
query: Read null like jq in key steps, comparisons and contains()Possibly taken @mojatter claimed this 1 day ago. Openbug
Difficulty 4/5 3-5 days Newbie friendliness 55/100
mojatter/tree#152 · 3 comments · 1 assignee ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 5/5 Over a week Newbie friendliness 35/100
Maintainers usually reply within 1 day
Similar issues
-
[flaky test] TestValidatorCommitterDropsEmptyStatusBatch: submits to the mock VC before its stream is registeredPossibly taken @liran-funaro claimed this today. Opencoordinator flaky-test race-condition testing
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
hyperledger/fabric-x-committer#876 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
garethgeorge/backrest#1426 ·
Maintainers usually reply within 1 day
-
enhancement nav-pilot
Difficulty 2/5 Half a day Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
valkey-io/valkey-operator#549 · 1 comment ·
Maintainers usually reply within 3 days
-
kind/features
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
TencentBlueKing/bk-nodemgr#3804 ·
Maintainers usually reply within 1 day