Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Ensure that YAML marshalling maintains field ordering #235

Open
Tracked by #206
elezar opened this issue Oct 22, 2024 · 5 comments · May be fixed by #236
Open
Tracked by #206

Ensure that YAML marshalling maintains field ordering #235

elezar opened this issue Oct 22, 2024 · 5 comments · May be fixed by #236

Comments

@elezar
Copy link
Contributor

elezar commented Oct 22, 2024

When outputing the following spec as YAML:

cdi.Spec{
	Version: "v0.3.0",
	Kind:    "example.com/class",
	ContainerEdits: cdi.ContainerEdits{
	DeviceNodes: []*cdi.DeviceNode{
		{
			Path: "/dev/foo",
		},
	},
}

We get the following output:

---
cdiVersion: v0.3.0
containerEdits:
  deviceNodes:
  - path: /dev/foo
devices: null
kind: example.com/class

Which does not maintain ordering of the fields as defines in the spec.

The JSON output is as follows:

{"cdiVersion":"v0.3.0","kind":"example.com/class","devices":null,"containerEdits":{"deviceNodes":[{"path":"/dev/foo"}]}}
@elezar
Copy link
Contributor Author

elezar commented Oct 22, 2024

@klihub @bart0sh what are youre thoughts here? I'm willing to concede that this isn't too important, but reading generated specs becomes cumbersome expecially since the kind information is at the end of the file.

@klihub
Copy link
Contributor

klihub commented Oct 22, 2024

And is the order even stable ? I think it might not be. If we can find a non-intrusive way of getting a desired ordering, then it is worth a shot, but I agree that this is not too high on the list of priority-ordered TODO list.

@elezar
Copy link
Contributor Author

elezar commented Oct 22, 2024

I was under the impression that for json files the ordering of the fields is stable and defined by the order in which they are defined in a struct. If one uses the standard go YAML library, then this is also the case, but it requires that one add explict YAML tags to the structs definitions.

@elezar elezar linked a pull request Oct 22, 2024 that will close this issue
@elezar
Copy link
Contributor Author

elezar commented Oct 22, 2024

I have created #236 as an example of the required changes.

@bart0sh
Copy link
Contributor

bart0sh commented Oct 23, 2024

I think it's quite important for people who prefer to use yaml. Preserving an order is much more readable.
Please, go ahead with #236.

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 a pull request may close this issue.

3 participants