ghodss/yaml

Unmarshal does not work if a field name differs from related annotation name

alexey-igrychev opened this issue · 1 comments

Yaml

apiVersion: v1
kind: Secret
metadata:
  name: registrysecret
  annotations:
    "helm.sh/hook": pre-install
type: kubernetes.io/dockerconfigjson

Struct

type Template struct {
  Version string `yaml:"apiVersion,omitempty"`
  Kind    string `yaml:"kind,omitempty"`
}

After unmarshaling (yaml.Unmarshal) the field Version is empty.
If the field is renamed to ApiVersion unmarshal works properly.

I used incorrect annotation yaml:"apiVersion,omitempty" instead of json:"apiVersion,omitempty".