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

Custom unmarshalling with support for known fields #1049

Open
ivankatliarchuk opened this issue Sep 24, 2024 · 1 comment
Open

Custom unmarshalling with support for known fields #1049

ivankatliarchuk opened this issue Sep 24, 2024 · 1 comment

Comments

@ivankatliarchuk
Copy link

I have something like this

in our code

func (t *TestJob) UnmarshalYAML(node *yaml.Node) error {
	type alias TestJob
	dataAlias := (*alias)(t)

	err := node.Decode(&dataAlias)
	if err != nil {
		return err
	}
	t.SetCapabilities()
	return nil
}

func Unmarshalling() {
  suite := TestSuite{
    chartRoute: chartRoute,
    fromRender: fromRender,
  }

  yamlDecoder := yaml.NewDecoder(strings.NewReader(content)) 
  yamlDecoder.KnownFields(true)

   if err := yamlDecoder.Decode(&suite); err != nil {
      return &suite, err
   }
}

Related #602 (comment)
So there is no way to throw an error in custom unmarshaller if there is an unknown field.

@ivankatliarchuk
Copy link
Author

Hi @niemeyer would you access a pull request or project is no longer maintained?

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

No branches or pull requests

1 participant