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

Add yaml struct tags for serialization to yaml #202

Closed
amisevsk opened this issue Oct 30, 2020 · 1 comment
Closed

Add yaml struct tags for serialization to yaml #202

amisevsk opened this issue Oct 30, 2020 · 1 comment
Labels
lifecycle/rotten Rotten items. These items have been stale for 60 days and are now closed. lifecycle/stale Stale items. These items have not been updated for 90 days.

Comments

@amisevsk
Copy link
Contributor

amisevsk commented Oct 30, 2020

edit: I found sigs.k8s.io/yaml which is used in this project for serialization/deserialization. This makes this functionality less important, but I'll leave it open in case there's any discussion to be had. Feel free to close issue if it's not applicable.


Apologies if this has been discussed before; I remember an issue in the past around this topic but can no longer find it.

Is your feature request related to a problem? Please describe.

Currently, go structs defined in pkg/apis define json tags for all fields to control serialization. However, go-yaml does not read these tags and instead depends on a similarly-structured yaml tag. The defaults for go-yaml are different (and quite bad) which makes serializing/deserializing instances of api structs difficult:

func main() {
	events := v1alpha2.Events{}
	events.PreStart = []string{"Command1", "Command2"}
	yaml, _ := yaml.Marshal(events) // using gopkg.in/yaml.v2
	json, _ := json.MarshalIndent(events, "", "  ")
	fmt.Println("yaml:\n", string(yaml))
	fmt.Println("json:\n", string(json))
}

will output:

yaml:
 workspaceevents:
  prestart:
  - Command1
  - Command2
  poststart: []
  prestop: []
  poststop: []

json:
 {
  "preStart": [
    "Command1",
    "Command2"
  ]
}

Describe the solution you'd like

Define matching yaml struct tags on go structs.

Describe alternatives you've considered

The issue can be worked around by using a package like https://github.com/ghodss/yaml/ but it appears to be unmaintained.

Additional context

I had to work around this issue in PR devfile/devworkspace-operator#188

Copy link

This issue is stale because it has been open for 90 days with no activity. Remove stale label or comment or this will be closed in 60 days.

@github-actions github-actions bot added the lifecycle/stale Stale items. These items have not been updated for 90 days. label Jul 10, 2024
@github-actions github-actions bot added the lifecycle/rotten Rotten items. These items have been stale for 60 days and are now closed. label Sep 8, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 8, 2024
@github-project-automation github-project-automation bot moved this to Done ✅ in Devfile Project Sep 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/rotten Rotten items. These items have been stale for 60 days and are now closed. lifecycle/stale Stale items. These items have not been updated for 90 days.
Projects
Status: Done ✅
Development

Successfully merging a pull request may close this issue.

1 participant