See code below for failing use case for go-json where it works in standard library.
I'm still trying to troubleshoot the root cause.
This issue came up when creating an interface for a go repository and one of their test cases were failing.
I've kept only the relevant code to recreate the issue.
The test also fails even if we have data no the string "{}"
Test with go v1.23, github.com/goccy/go-json v0.10.3
package main
import (
stdjson "encoding/json"
"fmt"
"github.com/goccy/go-json"
)
type SomeStruct struct {
Field string `json:"field"`
}
func (c *SomeStruct) Func1() {}
type SomeInterface interface {
Func1()
}
func main() {
var claims2 SomeInterface = &SomeStruct{}
err := stdjson.Unmarshal([]byte("{\"field\":\"value\"}"), &claims2)
if err == nil {
fmt.Println("Standard Library ok")
} else {
fmt.Println("Standard Library not ok")
}
err = json.Unmarshal([]byte("{\"field\":\"value\"}"), &claims2)
if err == nil {
fmt.Println("Goccy ok")
} else {
fmt.Printf("Goccy not ok, %v\n", err)
}
}
Standard Library ok
Goccy not ok, json: cannot unmarshal main.SomeInterface into Go value of type main.SomeInterface
See code below for failing use case for go-json where it works in standard library. I'm still trying to troubleshoot the root cause. This issue came up when creating an interface for a go repository and one of their test cases were failing. I've kept only the relevant code to recreate the issue. The test also fails even if we have data no the string "{}"
Test with go v1.23, github.com/goccy/go-json v0.10.3