Can't unmarshal multiple documents
rmb938 opened this issue · 10 comments
I have a yaml output that has multiple documents that I want to unmarshal.
When I try and unmarshal into a list I get this error
JSON: while decoding JSON: json: cannot unmarshal object into Go value of type []v1beta1.CustomResourceDefinition"}
github.com/go-logr/zapr.(*zapLogger).Error
/home/rbelgrave/go/pkg/mod/github.com/go-logr/zapr@v0.1.0/zapr.go:128
main.main
/home/rbelgrave/projects/github.com/rmb938/hostport-allocator/tools/crd-helm/main.go:32
runtime.main
/home/linuxbrew/.linuxbrew/Cellar/go/1.15/libexec/src/runtime/proc.go:204
exit status 1
the library does not support unmarshaling all the documents in an YAML multi doc, but if you pass a multi-doc it should still unmarshall the first document. see here:
https://play.golang.org/p/o-E1IUA7w1x
it manages to unmarshall the first document into A
, so not sure why are you seeing this error.
if you want to support multi-doc you should split the docs (around ---
) and unmarshall them separatelly.
/triage support
Ah yup I could do it that way.
I did figure out that gopkg.in/yaml.v2
does support decoding a multi-document yaml via the Decoder. Would it be possible to add that ability to this library?
potentially, but this library is primary used in kubernetes/kubernetes and there we already have code to split the documents and unmarshall separately, so in a way this is not very needed..
i can mark this as a feature request, but contributions would be appreciated.
/remove-triage support
/kind feature
/priority backlog
/help
@neolit123:
This request has been marked as needing help from a contributor.
Please ensure the request meets the requirements listed here.
If this request no longer meets these requirements, the label can be removed
by commenting with the /remove-help
command.
In response to this:
potentially, but this library is primary used in kubernetes/kubernetes and there we already have code to split the documents and unmarshall separately, so in a way this is not very needed..
i can mark this as a feature request, but contributions would be appreciated.
/remove-triage support
/kind feature
/priority backlog
/help
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.
Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale
.
Stale issues rot after an additional 30d of inactivity and eventually close.
If this issue is safe to close now please do so with /close
.
Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale
Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten
.
Rotten issues close after an additional 30d of inactivity.
If this issue is safe to close now please do so with /close
.
Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle rotten
Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen
.
Mark the issue as fresh with /remove-lifecycle rotten
.
Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close
@fejta-bot: Closing this issue.
In response to this:
Rotten issues close after 30d of inactivity.
Reopen the issue with/reopen
.
Mark the issue as fresh with/remove-lifecycle rotten
.Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.
potentially, but this library is primary used in kubernetes/kubernetes and there we already have code to split the documents and unmarshall separately, so in a way this is not very needed..
i can mark this as a feature request, but contributions would be appreciated.
/remove-triage support /kind feature /priority backlog /help
Just in case somebody is looking for this k8s code to split the documents: https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/apimachinery/pkg/util/yaml/decoder.go