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

[]*time.Time | panic: value method time.Time.MarshalJSON called using nil *Time pointer #523

Open
mirecl opened this issue Oct 3, 2024 · 0 comments

Comments

@mirecl
Copy link
Contributor

mirecl commented Oct 3, 2024

Example code with panic in go-json, but in encoding/json all good:

package main

import (
	"encoding/json"
	"fmt"
	"time"

	gojson "github.com/goccy/go-json"
)

func main() {
	data := []*time.Time{nil}

	b, _ := json.Marshal(data)
	fmt.Printf("std: %s\n", string(b))

	b, _ = gojson.Marshal(data)
	fmt.Printf("go-json: %s\n", string(b))
}

Output:

std: [null]
panic: value method time.Time.MarshalJSON called using nil *Time pointer

goroutine 1 [running]:
time.(*Time).MarshalJSON(0xc89e610?)
        <autogenerated>:1 +0x3a
github.com/goccy/go-json/internal/encoder.AppendMarshalJSON(0xc00007e8f0, 0xc000134300, {0xc000130000, 0x1, 0x400}, {0xc7c8e40?, 0x0?})
        /Users/mirecl/go/pkg/mod/github.com/goccy/[email protected]/internal/encoder/encoder.go:430 +0x276
github.com/goccy/go-json/internal/encoder/vm.appendMarshalJSON(0x0?, 0x0?, {0xc000130000?, 0x0?, 0x0?}, {0xc7c8e40?, 0x0?})
        /Users/mirecl/go/pkg/mod/github.com/goccy/[email protected]/internal/encoder/vm/util.go:152 +0x25
github.com/goccy/go-json/internal/encoder/vm.Run(0xc00007e8f0, {0xc000130000?, 0x0?, 0x400?}, 0xc00012e150?)
        /Users/mirecl/go/pkg/mod/github.com/goccy/[email protected]/internal/encoder/vm/vm.go:271 +0x217e
github.com/goccy/go-json.encodeRunCode(0xc00007e8f0?, {0xc000130000?, 0xc000104dc8?, 0xc00007c0c0?}, 0xc000130400?)
        /Users/mirecl/go/pkg/mod/github.com/goccy/[email protected]/encode.go:310 +0x56
github.com/goccy/go-json.encode(0xc00007e8f0, {0xc7a8320, 0xc000010090})
        /Users/mirecl/go/pkg/mod/github.com/goccy/[email protected]/encode.go:235 +0x205
github.com/goccy/go-json.marshal({0xc7a8320, 0xc000010090}, {0x0, 0x0, 0x1?})
        /Users/mirecl/go/pkg/mod/github.com/goccy/[email protected]/encode.go:150 +0xb9
github.com/goccy/go-json.MarshalWithOption(...)
        /Users/mirecl/go/pkg/mod/github.com/goccy/[email protected]/json.go:185
github.com/goccy/go-json.Marshal({0xc7a8320?, 0xc000010090?})
        /Users/mirecl/go/pkg/mod/github.com/goccy/[email protected]/json.go:170 +0x25
main.main()
        /Users/mirecl/Desktop/mapping/untitled folder/main.go:17 +0xb6
exit status 2
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