-
-
Notifications
You must be signed in to change notification settings - Fork 150
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
Decoding into interface bug #405
Comments
Solved! |
@mymmrac are you sure that the bug persists with the latest version? For me it works now. |
@GRbit yes, it reproduces, here is an example: package main
import (
// "encoding/json"
"fmt"
"github.com/goccy/go-json"
)
func main() {
s := Something{}
s.Thing = &ThingA{}
err := json.Unmarshal([]byte(`{"thing": {"a": 1}}`), &s)
if err != nil {
panic(err)
}
fmt.Println(s.Thing)
}
type Something struct {
Thing Thing `json:"thing"`
}
type Thing interface {
F()
}
type ThingA struct {
A int `json:"a"`
}
func (t *ThingA) F() {} With
With |
With this changes it works (from PR that was closed, #406):
|
@mymmrac Indeed, you are right. For some reason I thought that at some point it was fixed in goccy repository. Thank you for bringing this up again. |
When I tried to unmarshal bytes into a struct hidden under a specific interface, "go-json" failed to unmarshal it. At the same time, go standard lib or
json-iterator
feels just fine with this approach.Since you claim that your library is 100% compatible with the standard library, it makes sense to fix this bug or to change your README and add this exact case.
Code to reproduce the bug:
Output
If you change
doc
type name fromEsDocument
to justinterface{}
it'll work just fine.Output
The text was updated successfully, but these errors were encountered: