amazon-ion / ion-go

A Go implementation of Amazon Ion.
https://amazon-ion.github.io/ion-docs/
Apache License 2.0
173 stars 31 forks source link

#184: Allow custom unmarshal implementation #185

Closed errorhandler closed 2 years ago

errorhandler commented 2 years ago

Issue #, if available: #184

Description of changes: Adds the unmarshalling equivalent of Marshaler. Allowing types to implement their own unmarshalling logic. It's basically the same implementation, but requires the UnmarshalIon method to be implemented with a pointer receiver as it needs to mutate the struct.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

popematt commented 2 years ago

Hi, thanks for your contribution!

It looks like the CI build failed because one of our Github Workflows was broken. I've fixed the workflow now. Do you mind rebasing your commit against the tip of master in amzn/ion-go so that we can re-run with the fixed workflow? Alternately, you could grant me permission to edit the PR, and I'll update it.

Vingtoft commented 1 year ago

HI, can you please provide an example of how to use UnmarshalIon?

Given the struct:

type Account struct {
    Name         string          `ion:"name"`
}

I write the function:

func (a *Account) UnmarshalIon(b []byte) error {
    fmt.Println("In Unmarshall")
    a.Name = "boo"
    return nil
}

The above implementation does not work.

Needless to say: Im learning Go.

Thanks!