ohler55 / ojg

Optimized JSON for Go
MIT License
857 stars 49 forks source link

reflect.Value.Addr of unaddressable value Error #68

Closed Gusted closed 3 years ago

Gusted commented 3 years ago

Hello,

Since https://github.com/ohler55/ojg/releases/tag/v1.10.4-develop we are running into an error while Marshal-ing a struct which includes the time.Time

A very tiny reproduce-able case

type MinimalStyle struct {
    CreatedAt time.Time
}

func TestJSON(t *testing.T) {
    testCase := MinimalStyle{
        CreatedAt: time.Unix(0, 0),
    }
    _, err := oj.Marshal(testCase)
    if err != nil {
        t.Fatalf("Marshal error: %s", err)
    }
}

The stacktrace that was shown in the debugger seems to indicate the error originates from this line of code: https://github.com/ohler55/ojg/blob/10b6e9cb9f3f698966eb54ab45afa64e5f38ac72/oj/jsonmarshaler.go#L21

Callstack: image

Regards, Gusted

ohler55 commented 3 years ago

Thank you for the test case. I'll get it fixed. Might take a day or two.

ohler55 commented 3 years ago

The branch "can-not-addr" has the fix. If it works okay for you I'll release.

Gusted commented 3 years ago

Many thanks! That fixes the issue.

ohler55 commented 3 years ago

v1.12.3 released

Gusted commented 3 years ago

Thank you!