Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

🐛 Fix jMap struct field tags preserved. #652

Merged
merged 2 commits into from
Jun 12, 2024

Conversation

jortel
Copy link
Contributor

@jortel jortel commented Jun 11, 2024

Bug: File reaper json query:

SELECT count(*) 
FROM `Task` ,json_each(Attached) j0 
WHERE json_extract(j0.value,'$.id')=file.pk

not finding references which result in false orphans.

Fix:
Ensure struct tags are honored and preserved by jMap. For Attachments:

[
{"Activity":9,"ID":351,"Name":"ssh-agent.output"},
{"Activity":14,"ID":352,"Name":"git.output"},
{"Activity":19,"ID":353,"Name":"windup-shim.output"},
{"Activity":20,"ID":354,"Name":"settings.yaml"},
{"Activity":21,"ID":355,"Name":"konveyor-analyzer.output"},
{"Activity":23,"ID":356,"Name":"konveyor-analyzer-dep.output"}
]

MUST be stored as (with lower-case keys):

[
{"activity":9,"id":351,"name":"ssh-agent.output"},
{"activity":14,"id":352,"name":"git.output"},
{"activity":19,"id":353,"name":"windup-shim.output"},
{"activity":20,"id":354,"name":"settings.yaml"},
{"activity":21,"id":355,"name":"konveyor-analyzer.output"},
{"activity":23,"id":356,"name":"konveyor-analyzer-dep.output"}
]

else not found.

@@ -86,34 +86,35 @@ func (r jsonSerializer) jMap(in any) (out any) {
}
switch t.Kind() {
case reflect.Struct:
mp := make(map[string]any)
out = reflect.New(t).Interface()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

hint: Need to build a new struct (instead of map) to preserve field tags for json serializing.

Copy link
Collaborator

@mansam mansam left a comment

Choose a reason for hiding this comment

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

LGTM

jortel added 2 commits June 12, 2024 05:26
Signed-off-by: Jeff Ortel <jortel@redhat.com>
Signed-off-by: Jeff Ortel <jortel@redhat.com>
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants