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 Unmarshal not working #188

Closed
Vingtoft opened this issue Jan 4, 2023 · 3 comments
Closed

Custom Unmarshal not working #188

Vingtoft opened this issue Jan 4, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@Vingtoft
Copy link

Vingtoft commented Jan 4, 2023

Following this example, I have written the below code:

package main

import (
    "bytes"
    "fmt"

    "github.com/amzn/ion-go/ion"
)

func main() {
    UnmarshalCustomMarshaler()
}

type unmarshalMe struct {
    Name   string
    custom bool
}

func (u *unmarshalMe) UnmarshalIon(r ion.Reader) error {
    fmt.Print("UnmarshalIon called")
    u.custom = true
    return nil
}

func UnmarshalCustomMarshaler() {
    ionBinary, err := ion.MarshalBinary(unmarshalMe{
        Name: "John Doe",
    })
    if err != nil {
        fmt.Println("Error marshalling ion binary: ", err)
        panic(err)
    }

    dec := ion.NewReader(bytes.NewReader(ionBinary))
    var decodedResult unmarshalMe

    ion.UnmarshalFrom(dec, &decodedResult)
    fmt.Println("Decoded result: ", decodedResult)
}

Expected result is that u.custom is true, this is not the case: u.custom is false.

Is this a bug, or have i misunderstanded how to implement custom unmarshal?

@Vingtoft Vingtoft added the bug Something isn't working label Jan 4, 2023
@sjeandeaux
Copy link

Hi,

You should probably look at the version, you are using.
The latest version v1.1.3 does not contain the feature.

@Vingtoft
Copy link
Author

Vingtoft commented Jan 4, 2023

You are correct, thanks.

@popematt
Copy link
Contributor

popematt commented Feb 1, 2023

I've just released v1.2.0 which does contain the feature in #185.

@popematt popematt closed this as completed Feb 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants