We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
sample.go
package main import ( "encoding/json" "fmt" "time" ) type jsonTime time.Time func (j *jsonTime) UnmarshalJSON(b []byte) error { var n json.Number if err := json.Unmarshal(b, &n); err != nil { return err } var unix int64 if t, err := n.Int64(); err == nil { unix = t } else { f, err := n.Float64() if err != nil { return err } unix = int64(f) } *j = jsonTime(time.Unix(unix, 0)) return nil } type data struct { A jsonTime `json:"a"` B *jsonTime `json:"b"` } func main() { string := []byte(`{"a":1704303550,"b":1704303250}`) var parsed data err := json.Unmarshal(string, &parsed) fmt.Printf("Err: %v\n", err) fmt.Printf("a: %s\n", time.Time(parsed.A)) fmt.Printf("b: %v\n", time.Time(*parsed.B)) }
Err: <nil> a: 2024-01-03 17:39:10 +0000 UTC b: 2024-01-03 17:34:10 +0000 UTC
Err: json: cannot unmarshal string into Go struct field .a of type time.Time a: 0001-01-01 00:00:00 +0000 UTC panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x4be9ae]
v0.15.1
No response
The text was updated successfully, but these errors were encountered:
No branches or pull requests
The following program
sample.go
triggers an unexpected resultExpected result
Got
Yaegi Version
v0.15.1
Additional Notes
No response
The text was updated successfully, but these errors were encountered: