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

Library fails to unmarshal: cannot unmarshal main.SomeInterface into Go value of type main.SomeInterface #525

Open
orangeswim opened this issue Oct 14, 2024 · 2 comments

Comments

@orangeswim
Copy link

orangeswim commented Oct 14, 2024

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
@orangeswim orangeswim changed the title Library fails to Library fails to unmarshal: cannot unmarshal main.SomeInterface into Go value of type main.SomeInterface Oct 14, 2024
@SuperSandro2000
Copy link

I tried testing and benchmarking https://github.com/golang-jwt/jwt with goccy and hit the same error.

@SuperSandro2000
Copy link

Also probably a dupe of #443

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

2 participants